Re: Origin of size_t? Curious.
- From: "S.Tobias" <siXtY@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: 24 Jun 2005 07:14:32 GMT
pete <pfiland@xxxxxxxxxxxxxx> wrote:
> S.Tobias wrote:
> >
> > pete <pfiland@xxxxxxxxxxxxxx> wrote:
> > > N869
> > > 6.5.3.4 The sizeof operator
> > > [#2] The sizeof operator yields the size (in bytes) of its
> > > operand, which may be an expression or the parenthesized
> > > name of a type
> >
> > > If the size cannot be taken, then how can sizeof do
> > > what it's supposed to do?
> >
> > So what should a compiler do? Should it reject the code which
> > contains a declaration of type that is too large, or is it UB
> > applying `sizeof' to such type?
> My compiler accepts the oversized declaration,
> I just can't use it anywhere.
> When I uncomment array_5, i get:
> new.c(11) : error C2089: 'structure' : 'struct' too large
> /* BEGIN new.c */
> #include <stdio.h>
> struct structure {
> char array_0[(size_t)-1 / 5];
> char array_1[(size_t)-1 / 5];
> char array_2[(size_t)-1 / 5];
> char array_3[(size_t)-1 / 5];
> char array_4[(size_t)-1 / 5];
> /* char array_5[(size_t)-1 / 5];*/
> };
> int main(void)
> {
> printf("sizeof(array) is %lu\n",
> (long unsigned)sizeof(struct structure));
> return 0;
> }
> /* END new.c */
AFAICT this program is strictly conforming (I believe there're no limits
on size of types), and there is no reason to reject it, not at least
at the point of struct declaration. I think it's a defect in the Standard.
There's an interesting answer from Robert Gamble, pointing to DR266.
I think the Committee's response misses the point, but at least
it indicates there's no constraint violation there (diagnostics
is not required).
--
Stan Tobias
mailx `echo siXtY@xxxxxxxxxxxxxxxxxxxxxxxxxx | sed s/[[:upper:]]//g`
.
- References:
- Origin of size_t? Curious.
- From: Confused User
- Re: Origin of size_t? Curious.
- From: Gordon Burditt
- Re: Origin of size_t? Curious.
- From: S.Tobias
- Re: Origin of size_t? Curious.
- From: pete
- Re: Origin of size_t? Curious.
- From: S.Tobias
- Re: Origin of size_t? Curious.
- From: pete
- Origin of size_t? Curious.
- Prev by Date: Re: C software achitecture
- Next by Date: Re: C software achitecture
- Previous by thread: Re: Origin of size_t? Curious.
- Next by thread: Re: Origin of size_t? Curious.
- Index(es):
Relevant Pages
|