473,395 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

placement of volatile in typedef of struct

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.
Nov 14 '05 #1
5 6628
On 6 Feb 2004 16:56:41 -0800, jo************@lmco.com (Joe Pizzi)
wrote in comp.lang.c:
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.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #2
On Sat, 07 Feb 2004 04:02:00 GMT, Jack Klein <ja*******@spamcop.net>
wrote:
On 6 Feb 2004 16:56:41 -0800, jo************@lmco.com (Joe Pizzi)
wrote in comp.lang.c:
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.


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
le**@bdsoft.com
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
Nov 14 '05 #3
On Sat, 07 Feb 2004 04:21:07 GMT, Leor Zolman <le**@bdsoft.com> wrote:
CV qualifiers (what's the "R"?)
Found it, restrict. Haven't used that one much ;-)
-leor
Leor Zolman
BD Software
le**@bdsoft.com
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
le**@bdsoft.com
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
Nov 14 '05 #4
On Sat, 07 Feb 2004 04:21:07 GMT, Leor Zolman <le**@bdsoft.com> wrote
in comp.lang.c:
On Sat, 07 Feb 2004 04:02:00 GMT, Jack Klein <ja*******@spamcop.net>
wrote:
On 6 Feb 2004 16:56:41 -0800, jo************@lmco.com (Joe Pizzi)
wrote in comp.lang.c:
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.


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.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #5
On Sat, 07 Feb 2004 05:32:42 GMT, Jack Klein <ja*******@spamcop.net>
wrote:

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.


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

Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Anh-Tu Vo | last post by:
Hi all, I have a weird problem on a variable assignment. It seems that the variable is only updated with the value at the second time the function is called. My program looks like this: ...
23
by: Giancarlo Niccolai | last post by:
Hello all. I have peeked through the FAQ and all relevant links, and also through Stroustrup book, but I have not been able to find an answer, so I have to post here as a last resort. It...
4
by: dwaach | last post by:
Hi, I have something like. struct X {}; X ox; X* pox=&ox; X*& volatile r =pox;
3
by: Mark A. Odell | last post by:
If I have a structure that may point to a volatile "region (e.g. device)" or a context in memory what would be the best way to use the volatile keyword? E.g. a) volatile on struct objects ...
14
by: Ian Pilcher | last post by:
It's pretty common to see declarations such as: static volatile sig_atomic_t caught_signal = 0; C99 defines sig_atomic_t as a "... (possibly volatile-qualified) integer type of an object that...
5
by: ma740988 | last post by:
I've got a struct which is comprised of POD types. I know in advance where in memory the struct resides. To make a long story short, I'm doing transfers of 16 bit ADC sampled data between...
13
by: Samshayam | last post by:
I have come across the application of placement new in memory mapped i/o in a number of books.I am not able to understand it completely, may be becaues of my lack of knowledge with memory mapped...
6
by: red floyd | last post by:
I have a struct that maps onto a set of memory mapped registers. I access this via a pointer. Is it better to declare it as pointer to a volatile struct, or to declare the individual members as...
16
by: Ark Khasin | last post by:
I have a memory-mapped peripheral with a mapping like, say, struct T {uint8_t read, write, status, forkicks;}; If I slap a volatile on an object of type struct T, does it guarantee that all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.