Re: Origin of size_t? Curious.



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`
.



Relevant Pages

  • Re: How to pass a struct to a function
    ... write an expression evaluating to your struct -- the name of a variable ... you haven't declared a type "struct entry". ... about how this declaration is handled, ... on which compiler you're using, but any decent compiler will print ...
    (comp.lang.c)
  • Re: void * vs char *
    ... cast p to a (struct s*) to avoid a compile-time error. ... struct s {int a;}; ... function call consists solely of an identifier, and if no declaration ... And see what your compiler has to say. ...
    (comp.lang.c)
  • Re: Origin of size_t? Curious.
    ... >>> If the size cannot be taken, then how can sizeof do ... >> contains a declaration of type that is too large, ... > My compiler accepts the oversized declaration, ... Several such arrays ...
    (comp.lang.c)
  • Some issues with using sizeof() in template definitions
    ... I have two issues with VC++, which might or might not be related, but both have to do with using the sizeof inside template definitions. ... When using sizeof inside my allocator, such as to assign to an enum value defined in the class, the compiler complains about errors in. ... templatestruct MemberCheck ...
    (microsoft.public.vc.language)
  • my wits end - compiling 8.4.9
    ... and never had an issue even on the same OS and compiler version. ... checking whether struct tm is in sys/time.h or time.h... ... checking for gettimeofday declaration... ...
    (comp.lang.tcl)