Mail Archives: djgpp/1998/01/22/12:00:33
A. Sinan Unur wrote:
>
> Scott Warner wrote:
> >
> > something like
> >
> > #include<stdio.h>
> >
> > int main(void)
> > {
> > int i;
> > char c;
> > float f;
> >
> > printf("Size of integer: %d\n", sizeof(i);
> > printf("Size of char: %d\n", sizeof(c);
> > printf("Size of float: %d\n", sizeof(f);
> >
> > return 0;
> > }
> >
>
> you don't need to declare any variables. sizeof(type) is a constant
> expression of size_t. incidentally, did you try to compile the above
> with -Wall?
>
> printf("Size of integer: %lu\n", sizeof(int);
> printf("Size of char: %lu\n", sizeof(char);
> printf("Size of float: %lu\n", sizeof(float);
>
> etc. is fine.
>
For a truly conforming program each sizeof(...) should be
preceeded by (unsigned long) to ensure that it is cast
correctly to the type expected in the printf format string.
There is no guarantee that a result of type size_t is an
unsigned long (even though it happens to be in the current
version of DJGPP). I believe the trailing parenthesis has
been dealt with elsewhere.
Simon.
- Raw text -