[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in doprnt.c?



Yves Pelletier <ypell@cam.org> writes:

|> While experimenting with -mshort, I wrote this simple test
|> program:

|> #include <stdio.h>
|> main()
|> {
|> printf ("int: %d bytes\n, sizeof (int));
|> printf ("long: %d bytes\n, sizeof (long));
|> printf ("long long: %d bytes\n, sizeof (long long));
|> }

You use the wrong formats.  sizeof yields a value of type size_t, which is
32 bits with or without -mshort.  To be fully correct, you must use %ld
*and* cast the value to long, because you don't know how big size_t is in
general.


#include <stdio.h>
main()
{
  printf ("int: %ld bytes\n, (long) sizeof (int));
  printf ("long: %ld bytes\n, (long) sizeof (long));
  printf ("long long: %ld bytes\n, (long) sizeof (long long));
}


Andreas.