This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: sizeof((..))
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Ralf Corsepius <ralf dot corsepius at rtems dot org>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Mon, 31 Jan 2011 09:19:07 +0000
- Subject: Re: sizeof((..))
- References: <4D467A0C.2080708@rtems.org>
On 31 January 2011 08:59, Ralf Corsepius <ralf.corsepius@rtems.org> wrote:
> Hi,
>
> gcc emits an error, when compiling this code-snippet:
>
> --- snip ---
> extern int x;
>
> void
> foo (void)
> {
> ?x = sizeof ((long));
> }
> --- snip ---
>
> # gcc -Wall -o tmp.o -c tmp.c
> tmp.c: In function ‘foo’:
> tmp.c:6:21: error: expected expression before ‘)’ token
>
> # gcc --version
> gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
>
> # sparc-rtems4.11-gcc -Wall -o tmp.o -c tmp.c
> tmp.c: In function 'foo':
> tmp.c:6:21: error: expected expression before ')' token
>
> # sparc-rtems4.11-gcc --version
> sparc-rtems4.11-gcc (GCC) 4.5.2 20101216 (RTEMS
> gcc-4.5.2-3.fc14/newlib-1.19.0-1.fc14)
>
>
> Any explanations? What is wrong?
The code is wrong. sizeof expects either an expression, or a
parenthesized type-id. (long) is not a type-id so ((long)) is not a
parenthesized type-id, therefore it must be interpreted as an
expression, but it's not a valid expression either.