Dave Hansen <> writes:
> On Jun 26, 3:43 am, Richard Heathfield <r...@see.sig.invalid> wrote:
>> 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)
kst- <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"