Re: Order of evaluation.
From: B. v Ingen Schenau (bart_at_ingen.ddns.info)
Date: 02/11/04
- Next message: Richard Heathfield: "Re: Order of evaluation."
- Previous message: tom_usenet: "Re: Order of evaluation."
- In reply to: Jason: "Re: Order of evaluation."
- Next in thread: Jason: "Re: Order of evaluation."
- Reply: Jason: "Re: Order of evaluation."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 11 Feb 2004 19:21:46 +0100
Jason wrote:
> "Richard Heathfield" <invalid@address.co.uk.invalid> wrote in message
> news:402a4aec@news2.power.net.uk...
>> Jason wrote:
>> > Good job I didn't write this then, which I believe is also valid, but
>> > unnecessary ( sizeof introduces the tag name a_struct in this context
>> > ):
>> >
>> > {
>> > size_t size = sizeof ( struct a_struct { int a; } );
>> >
>> > s = malloc( sizeof (a_struct) );
>> > }
>>
>> I think you might want to run this one by your compiler before you get
>> too fond of it. :-)
>
> Ah - it doesn't work then? I am not fond of it (never tried it). I read
> that in 1994, Samuel P. Harbison, et al., "C A Reference Manual", ISBN
> 0-13-326224-3, page 196
>
> "The effect of sizeof(struct S {int a,b;} ) is to create a new type [S] in
> ISO C, [cut], the type can be referenced later in the source file."
>
> Took me ages to find that reference.
It does not work, because in C a struct definition does not create a new
typename. Any struct-types you have defined must be referenced with the
keyword struct in place.
This code does work (at most it gives warnings about unused variables):
#include <stdlib.h>
int main()
{
size_t size = sizeof ( struct a_struct { int a; } );
void* s = malloc( sizeof (struct a_struct) );
}
Bart v Ingen Schenau
-- a.c.l.l.c-c++ FAQ: http://www.snurse-l.org/acllc-c++/faq.html (currently unavailable) a.c.l.l.c-c++ FAQ mirror: http://www.inglorion.com/acllcc++.html c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
- Next message: Richard Heathfield: "Re: Order of evaluation."
- Previous message: tom_usenet: "Re: Order of evaluation."
- In reply to: Jason: "Re: Order of evaluation."
- Next in thread: Jason: "Re: Order of evaluation."
- Reply: Jason: "Re: Order of evaluation."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|