In article < .com>
chandanlinster <> wrote:
>Consider the following program fragment:
> struct some_struct { } a;
> printf("%d", sizeof(a));
>On GCC 4.1.1 the output is 0(zero).
I do not actually have gcc 4.1.1 handy, but I do not believe this
is the case. Note that to get gcc to compile C code (as opposed to
some other language that looks a lot like C, but is not actually C)
you must give it the "-ansi -pedantic" options, and if you do so:
% strictcc t.c
t.c:1: error: struct has no members
(where "strictcc" is "cc -ansi -pedantic -Werror" with the stderr
stream massaged to change the string "warning" to "error":
% cat ~/scripts/strictcc
#! /bin/sh
(cc -ansi -pedantic -Werror ${1+"$@"} 2>&1) |
sed -e 1d -e s/warning:/error:/
# it might be reasonable to add 1>&2 but this suffices for now
If gcc ever claims full C99 conformance, you can use -std=c99
instead of -ansi or -std=c89, presumably still with -pedantic,
to get a strict C99 compiler.)
>On another compiler {sorry I don't know the compiler
} the output
>is 1(one).
This would be correct for a C++ compiler -- are you sure you invoked
a C compiler? (Note that, as with gcc, you may have to supply
various command-line arguments to get compiler for the C language,
rather than one for some other language that looks a lot like C,
but is different.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.