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. 5 6647
On Sat, 07 Feb 2004 04:02:00 GMT, Jack Klein <ja*******@spam cop.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
On Sat, 07 Feb 2004 04:21:07 GMT, Leor Zolman <le**@bdsoft.co m> wrote: CV qualifiers (what's the "R"?)
Found it, restrict. Haven't used that one much ;-)
-leor
Leor Zolman BD Software le**@bdsoft.co m 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
On Sat, 07 Feb 2004 04:21:07 GMT, Leor Zolman <le**@bdsoft.co m> wrote
in comp.lang.c: On Sat, 07 Feb 2004 04:02:00 GMT, Jack Klein <ja*******@spam cop.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.l earn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
On Sat, 07 Feb 2004 05:32:42 GMT, Jack Klein <ja*******@spam cop.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:
myClass
{
typedef struct
{
|
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 makes sense that if you have virtual destructors, they are eventually
used in the explicit destructor call when using the placement new semantic:
class A {
|
by: dwaach |
last post by:
Hi,
I have something like.
struct X {};
X ox;
X* pox=&ox;
X*& volatile r =pox;
|
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
struct Foo
{
|
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 can be accessed as an atomic entity, even in the
presence of asynchronous interrupts."
Does this mean that the use of "volatile" in the above declaration is
redundant? (It sure sounds that way to me.)
| |
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 'cards'. At the
front end I configure the memory such that - say card 1 will transfer
data to card 2 at a specified region. A header is accompanied with
each data transfer. So now lets say card 1 transferred the header to
location 0xD0000000 of...
|
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 i/o.In my
understanding it is a system where I/O devices are treated as memory
locations and are addressed using same number of address lines.How an
object placed at a specific location makes a difference to this?Some
body pls clarify?
|
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 volatile?
That is to say, which is likely to be better/less error prone:
struct registers {
unsigned long reg1;
|
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 accesses to the members are byte-wide, or is the compiler free
to read or read-modify-write in any data width it chooses?
Is slapping a volatile on each member of the struct definition any
different? better? worse?
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |