placement of volatile in typedef of struct

J

Joe Pizzi

Is there any difference between the following two definitions? If so,
can you explain them to me?

typedef volatile struct
{
int x;
} VS_Def;

typedef struct
{
int x;
} volatile SV_Def;

Thanks.
 
J

Jack Klein

Is there any difference between the following two definitions? If so,
can you explain them to me?

typedef volatile struct
{
int x;
} VS_Def;

typedef struct
{
int x;
} volatile SV_Def;

Thanks.

They are both extremely bad programming practice. CVR qualifiers and
in most cases pointers should NEVER be hidden behind typedefs. They
rapidly become a maintenance nightmare.

Beyond that, the first one is legal C and the second is a syntax
error.
 
L

Leor Zolman

They are both extremely bad programming practice. CVR qualifiers and
in most cases pointers should NEVER be hidden behind typedefs. They
rapidly become a maintenance nightmare.

Beyond that, the first one is legal C and the second is a syntax
error.

Not sure I see how it is a syntax error; 6.7/1 doesn't seem to impose
any ordering requirements on all the different flavors of declaration
specifiers, so does it matter whether CV qualifiers come before or
after struct-or-union-specifiers?

Comeau doesn't even raise a warning on it.

That aside, I agree wholeheartedly with the advice against putting CV
qualifiers (what's the "R"?) anywhere except in plain view near the
declarator they appy to.
-leor

Leor Zolman
BD Software
(e-mail address removed)
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html
 
L

Leor Zolman

CV qualifiers (what's the "R"?)

Found it, restrict. Haven't used that one much ;-)
-leor
Leor Zolman
BD Software
(e-mail address removed)
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html

Leor Zolman
BD Software
(e-mail address removed)
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html
 
J

Jack Klein

Not sure I see how it is a syntax error; 6.7/1 doesn't seem to impose
any ordering requirements on all the different flavors of declaration
specifiers, so does it matter whether CV qualifiers come before or
after struct-or-union-specifiers?

Comeau doesn't even raise a warning on it.

OK, you caught me. Looking at the grammar, I think it is probably
quite legal. Just this once I threw it into a compiler and watched
what happened, and noticed that it kicked out an error message. That
and the prohibition against more than one storage class specifier
appearing in a declaration.
That aside, I agree wholeheartedly with the advice against putting CV
qualifiers (what's the "R"?) anywhere except in plain view near the
declarator they appy to.
-leor

I see from your own follow-up that you found it applied to the new C99
keyword restrict.
 
L

Leor Zolman

OK, you caught me. Looking at the grammar, I think it is probably
quite legal.

I watched the original post sit there for hours, and wanted to reply
that the two statements were equivalent, but I'd gotten just a bit
gun-shy after several recent gaffes. Finally, seeing no one had
responded, I looked it up in the standard to my own satisfaction,
wrote it up, and was about to send it off when your post showed up. So
then I went back to the drawing board and studied it some more....

That I saw this straight off I probably have Dan Saks to thank for.
He wrote a 5-day Advanced C course last year in direct response to a
call I put out for one; in that course, he has students write their
own C declaration parsers, building them up bit-by-bit until they
handle stuff that gets pretty darned hairy. This is somewhat congruent
to the series of articles he wrote for CUJ in an attempt to de-mystify
C++ declaration syntax.

Let's just say that I never thought the day would come that I'd
actually be able to remember the difference between
declaration-specifiers and declarators, but after teaching that
course, even a year later, I still do remember. Amazing... ;-)
-leor
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top