Initializing compound type containing opaque type

S

Szabolcs Nagy

Nate said:
Is it really? gcc -ansi -pedantic accepts it.

i haven't checked the standard (but i remember getting warning for it
with gcc -Wall) now i'm not sure, will check it later
 
N

Nate Eldredge

Keith Thompson said:
Nate Eldredge said:
Thanks. I bit the bullet and bought a copy of the standard, and now
it makes sense.
[...]

I hope you knew that a post-standard draft, which includes the C99
standard with the three Technical Corrigenda merged into it, is
available at no charge at
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf>.

Hm. Oh well, I'll consider it a US$30 donation to ANSI, they're a
worthy cause. Might be nice if the FAQ mentioned the draft, however.
The clc-wiki page has a link, I see, but doesn't explain very clearly
what it is.
 
F

Flash Gordon

Szabolcs Nagy wrote, On 04/10/08 06:50:
i haven't checked the standard (but i remember getting warning for it
with gcc -Wall) now i'm not sure, will check it later

Compilers are allowed to warn about anything they feel like, so a
compiler warning about something does *not* mean that it is necessarily
invalid, although you should always check the code generating a warning
very carefully and understand *why* the compiler is generating a warning
because often it indicates a real problem.

Conversely, a compiler accepting a program without warning and producing
an executable that works is no guarantee that the program is correct.
The standard does not require warnings for all problems and it is not
practical for a compiler to generate warnings for all possible problems,
and some errors will only trigger a failure under obscure conditions or
if the compiler tries a particularly clever (and valid) optimisation.

In this case, using {0} as an initialiser is valid.
 
D

David Thompson

As already noted, only for auto. Designated-initializer syntax (the
part in the braces) directly as an initializer, not a compound
literal, works in all (C99) cases.
I think you mean

struct foo blah = *(struct foo[]){ { .a = 17, .b = 23 } };

I doubt it. This does not work any better (though not any worse
either) and is unnecessarily cluttered.

- formerly david.thompson1 || achar(64) || worldnet.att.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top