473,231 Members | 2,035 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,231 software developers and data experts.

Structure members and reserved identifiers

Hello all,

I've been wondering about struct member names and reserved identifiers
for some time now and I can't figure out whether the reserved identifier
restrictions apply to struct members.

I think the following is allowed:

struct foo {
unsigned char *memory;
};

Since struct members are in a different namespace from (than?) function
names, the member name 'memory' would not invade the implementations
namespace 'mem[a-z]*'.

Until now I've refrained from using member names such as 'string' and
'memory', just to be on the safe side, but sometimes such names are the
most descriptive for the data they represent.

I've been reading through the standard (n1124 draft) and my books on C
(K&R2 and 'Expert C Programming' by Peter van der Linden) but I can't
find a satisfactory answer.
So if anyone could shed some light on this issue, I would be much obliged,

Bas Wassink
Jun 26 '07 #1
4 1765
Bas Wassink said:
Hello all,

I've been wondering about struct member names and reserved identifiers
for some time now and I can't figure out whether the reserved
identifier restrictions apply to struct members.
They don't (although I'd still steer clear of keywords if I were you!).

The crux is that the kind of names you're (laudably) worrying about,
str*, mem*, to*, is*, and so on, are reserved for use as ***external
identifiers***. Each struct carries its own name space around, so
you're okay with a struct member called 'memory' (or indeed 'member').
You can also have struct members called 'towel', 'isobar', and
'strange_attractor' if you like.

The relevant text in C89 begins with:

4.13 FUTURE LIBRARY DIRECTIONS

The following names are grouped under individual headers for
convenience. All external names described below are reserved no
matter what headers are included by the program.

The relevant text in C99 begins with:

7.26 Future library directions

1 The following names are grouped under individual headers for
convenience. All external names described below are reserved no matter
what headers are included by the program.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 26 '07 #2
On Tue, 26 Jun 2007 08:43:10 +0000, Richard Heathfield wrote:
Bas Wassink said:
>Hello all,

I've been wondering about struct member names and reserved identifiers
for some time now and I can't figure out whether the reserved
identifier restrictions apply to struct members.

They don't (although I'd still steer clear of keywords if I were you!).
I certainly won't use those as member names, that would only cause
confusion.
The crux is that the kind of names you're (laudably) worrying about,
str*, mem*, to*, is*, and so on, are reserved for use as ***external
identifiers***. Each struct carries its own name space around, so you're
okay with a struct member called 'memory' (or indeed 'member'). You can
also have struct members called 'towel', 'isobar', and
'strange_attractor' if you like.

The relevant text in C89 begins with:

4.13 FUTURE LIBRARY DIRECTIONS

The following names are grouped under individual headers for
convenience. All external names described below are reserved no matter
what headers are included by the program.

The relevant text in C99 begins with:

7.26 Future library directions

1 The following names are grouped under individual headers for
convenience. All external names described below are reserved no matter
what headers are included by the program.
Right, the word *external* in those sections lead me to believe I could
indeed use things like 'string' and 'token' as struct member names, but I
wanted to be sure, that's why I thought I'd ask the experts.

Thank you very much,

Bas Wassink
Jun 26 '07 #3
On Jun 26, 3:43 am, Richard Heathfield <r...@see.sig.invalidwrote:
Bas Wassink said:
Hello all,
I've been wondering about struct member names and reserved identifiers
for some time now and I can't figure out whether the reserved
identifier restrictions apply to struct members.

They don't (although I'd still steer clear of keywords if I were you!).

The crux is that the kind of names you're (laudably) worrying about,
str*, mem*, to*, is*, and so on, are reserved for use as ***external
identifiers***. Each struct carries its own name space around, so
you're okay with a struct member called 'memory' (or indeed 'member').
You can also have struct members called 'towel', 'isobar', and
'strange_attractor' if you like.
But beware of reserved macro names if the associated header is
included. Macros don't respect namespaces.

Regards,

-=Dave
Jun 26 '07 #4
Dave Hansen <id**@hotmail.comwrites:
On Jun 26, 3:43 am, Richard Heathfield <r...@see.sig.invalidwrote:
>Bas Wassink said:
I've been wondering about struct member names and reserved identifiers
for some time now and I can't figure out whether the reserved
identifier restrictions apply to struct members.

They don't (although I'd still steer clear of keywords if I were you!).

The crux is that the kind of names you're (laudably) worrying about,
str*, mem*, to*, is*, and so on, are reserved for use as ***external
identifiers***. Each struct carries its own name space around, so
you're okay with a struct member called 'memory' (or indeed 'member').
You can also have struct members called 'towel', 'isobar', and
'strange_attractor' if you like.

But beware of reserved macro names if the associated header is
included. Macros don't respect namespaces.
Right, but if mem* and friends are defined as macros, they're defined
as function-like macros.

But you can still run into problems if you use one of those identifers
as a member name, if the member is a function pointer. For example:

#include <string.h>
/* Assume the implementation defines a function memfoo(), and
additionally defines an equivalent function-like macro. */

struct mystruct {
void (*memfoo)(void);
}
struct mystruct obj;
/* ... */
obj.memfoo(); /* This invokes the macro! */

If you *don't* include <string.h>, either directly or indirectly,
there's no conflict with the external function.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 26 '07 #5

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

Similar topics

5
by: kazack | last post by:
I am a little confused with code I am looking at. My c++ book does not go into passing a structure to a function so I pulled out a c book which does. and I do not understand the prototype verses...
10
by: tapeesh | last post by:
I created a C file say struct.c with the following structure declarations in the same file struct A { union key { int i; float f; }k1;
31
by: metaperl | last post by:
-- python -i File "<stdin>", line 1 class = "algebra" ^ SyntaxError: invalid syntax Why isn' t the parser smart enough to see that class followed by an identifier is used for class...
2
by: the_init | last post by:
Hi friends, OS: Netware Compiler: Watcom 11.0 I am using athe following structure in my program. But when I compile it is giving Error: E1172 Expected struct or union tag but found 0x08 at...
8
by: Tim H | last post by:
I know C's rules about reserved identifiers (anything starting with "_", leading "is", etc). I don't know C++ rules. I assume the same rules and more apply? I've seen several conventions for...
6
by: noone | last post by:
What is the syntax to access members of a structure without explicitly naming the structure in every access? struct mytype { int a; char* b; long c; } IT; How can I access the structure...
9
by: nolonger | last post by:
Sample code:- typedef struct __Y { int a; char b; } Y; Y my_struct; Y *my_ptr_struct;
6
by: Scoots | last post by:
I know the usually applied workaround for multiple definitions of header files, but I have a problem on this one. This time, I can't just ifndef the header file that defines my structure. So...
0
by: Gordon Burditt | last post by:
>----------------------------- 8< ---------------------------------- Not if you include <string.h>, in which case the second paragraph above is an issue. Otherwise, it's OK. It's OK, but I...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.