473,421 Members | 1,668 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,421 software developers and data experts.

Macros that break compiler headers

Hello,

I recently came across code that defined a peculiar macro:

#define local static

gcc had no problem with it, but another (experimental) compiler I am
evaluating output a lengthy list of errors.

Apparently, the identifier 'local' is used in several places within that
compiler's headers. Hell breaks loose when the identifier is changed to
a reserved keyword.

Should the compiler implementers be more careful in their choice of
identifiers, or is the macro definition somehow illegal?

--
Regards, Grumble
Nov 14 '05 #1
16 1459
On Thu, 16 Dec 2004 11:08:53 +0100, Grumble wrote:
Hello,

I recently came across code that defined a peculiar macro:

#define local static

gcc had no problem with it, but another (experimental) compiler I am
evaluating output a lengthy list of errors.

Apparently, the identifier 'local' is used in several places within that
compiler's headers. Hell breaks loose when the identifier is changed to
a reserved keyword.

Should the compiler implementers be more careful in their choice of
identifiers, or is the macro definition somehow illegal?


It looks fine to me. I couldn't find any sets of reserved identifiers that
can match local. So the implementation should not be using it.

Lawrence

Nov 14 '05 #2
In article <pa****************************@netactive.co.uk> ,
Lawrence Kirby <lk****@netactive.co.uk> wrote:
....
Apparently, the identifier 'local' is used in several places within that
compiler's headers. Hell breaks loose when the identifier is changed to
a reserved keyword.

Should the compiler implementers be more careful in their choice of
identifiers, or is the macro definition somehow illegal?


It looks fine to me. I couldn't find any sets of reserved identifiers that
can match local. So the implementation should not be using it.


But that does leave open this gap - which I find annoying - in C. Which is
that you can't ever really be sure what is reserved and what isn't - other
than by constantly keeping up with standards documents and/or posting (and
getting flamed) here.

The OP posted a similar item in c.u.p. about code that defined (or
typedef'd - not sure which) the word "stat" and this caused problems
(basically, because the "experimental compiler" automatically included
stat.h). It seems to me that languages ought to make better provisions for
separating the programmers and implementors namespaces. I suppose it is
too late for C.

Would it work if all user symbols started with a capital letter?

Nov 14 '05 #3
Grumble <de*****@kma.eu.org> wrote:
I recently came across code that defined a peculiar macro:

#define local static

gcc had no problem with it, but another (experimental) compiler I am
evaluating output a lengthy list of errors.

Apparently, the identifier 'local' is used in several places within that
compiler's headers. Hell breaks loose when the identifier is changed to
a reserved keyword.

Should the compiler implementers be more careful in their choice of
identifiers, or is the macro definition somehow illegal?


It's the implementation's fault. It would probably have the same, or
similar, problems with declarations like

int *local;

or

void local(char *txt, int len);

placed before its headers. All of those, including your #define, are
perfectly legal; the implementation is to keep its paws off identifiers
which are not reserved for its use, of which local is one.

Richard
Nov 14 '05 #4
ga*****@yin.interaccess.com (Kenny McCormack) wrote:
In article <pa****************************@netactive.co.uk> ,
Lawrence Kirby <lk****@netactive.co.uk> wrote:
It looks fine to me. I couldn't find any sets of reserved identifiers that
can match local. So the implementation should not be using it.
But that does leave open this gap - which I find annoying - in C. Which is
that you can't ever really be sure what is reserved and what isn't - other
than by constantly keeping up with standards documents and/or posting (and
getting flamed) here.


Constantly? There's only two Standards, plus a couple of DRs which,
TTBOMK, don't add any reserved identifiers. How hard is it to keep up
with those?
The OP posted a similar item in c.u.p. about code that defined (or
typedef'd - not sure which) the word "stat" and this caused problems
(basically, because the "experimental compiler" automatically included
stat.h).
Then that compiler is broken, not the code.
Would it work if all user symbols started with a capital letter?


Absolutely not. I refuse to make my code uglier for no good reason. If
you want to go that way at all, you should make all implementation
symbols start with a capital, since there are fewer of them than there
are user symbols. Even that would be a pain, since I now like to use
capitalised names for those occasions when I use typedef.

Richard
Nov 14 '05 #5
On Thu, 16 Dec 2004 13:24:51 GMT, in comp.lang.c ,
ga*****@yin.interaccess.com (Kenny McCormack) wrote:
But that does leave open this gap - which I find annoying - in C. Which is
that you can't ever really be sure what is reserved and what isn't
Show me a language in which this isn't the case.
- other
than by constantly keeping up with standards documents and/or posting (and
getting flamed) here.


And.... ?

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #6
In article <mb********************************@4ax.com> Mark McIntyre <ma**********@spamcop.net> writes:
On Thu, 16 Dec 2004 13:24:51 GMT, in comp.lang.c ,
ga*****@yin.interaccess.com (Kenny McCormack) wrote:
But that does leave open this gap - which I find annoying - in C. Which is
that you can't ever really be sure what is reserved and what isn't


Show me a language in which this isn't the case.


Algol 60, Fortran.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 14 '05 #7
"Dik T. Winter" <Di********@cwi.nl> wrote:
In article <mb********************************@4ax.com> Mark McIntyre <ma**********@spamcop.net> writes:
> On Thu, 16 Dec 2004 13:24:51 GMT, in comp.lang.c ,
> ga*****@yin.interaccess.com (Kenny McCormack) wrote:
>
> >But that does leave open this gap - which I find annoying - in C. Which is
> >that you can't ever really be sure what is reserved and what isn't

>
> Show me a language in which this isn't the case.


Algol 60, Fortran.


From the 1977 Fortran Standard:

# A2. Conflicts with ANSI X3.9-1966

# (22) More intrinsic function names have been added and could conflict
# with the names of subprograms. These names are ACOS, ANINT, ASIN,
# CHAR, COSH, DACOS, DASIN, DCOSH, DDIM, DINT, DNINT, DPROD,
# DSINH, DTAN, DTANH, ICHAR, IDNINT, INDEX, LEN, LGE, LGT,
# LLE, LLT, LOG, LOG10, MAX, MIN, NINT, SINH, and TAN.

I don't see how this is different from the situation with C89 and C99.
As for Algol 60, specifying the year is cheating. You might as well say
that there are no different versions of C89.

Richard
Nov 14 '05 #8
Richard Bos wrote:
Grumble wrote:
I recently came across code that defined a peculiar macro:

#define local static

gcc had no problem with it, but another (experimental) compiler I
am evaluating output a lengthy list of errors.

Apparently, the identifier 'local' is used in several places within
that compiler's headers. Hell breaks loose when the identifier is
changed to a reserved keyword.

Should the compiler implementers be more careful in their choice of
identifiers, or is the macro definition somehow illegal?
It's the implementation's fault. It would probably have the same, or
similar, problems with declarations like

int *local;

or

void local(char *txt, int len);

placed before its headers.


As far as I understand, 'local' is only used as an auto variable in
the compiler's implementation. Thus your two examples would not be a
problem, right?
All of those, including your #define, are perfectly legal; the
implementation is to keep its paws off identifiers which are not
reserved for its use, of which local is one.


OK. What about

#define int const long
#define unsigned
#define extern static
#define double my_double
#define else

I imagine /they/ are explicitely forbidden?

--
Regards, Grumble
Nov 14 '05 #9
In article <41****************@news.individual.net> rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
"Dik T. Winter" <Di********@cwi.nl> wrote: ....
>But that does leave open this gap - which I find annoying - in C.
>Which is that you can't ever really be sure what is reserved and
>what isn't

.... From the 1977 Fortran Standard:

# A2. Conflicts with ANSI X3.9-1966

# (22) More intrinsic function names have been added and could conflict
# with the names of subprograms. These names are ACOS, ANINT, ASIN,
# CHAR, COSH, DACOS, DASIN, DCOSH, DDIM, DINT, DNINT, DPROD,
# DSINH, DTAN, DTANH, ICHAR, IDNINT, INDEX, LEN, LGE, LGT,
# LLE, LLT, LOG, LOG10, MAX, MIN, NINT, SINH, and TAN.

I don't see how this is different from the situation with C89 and C99.
But those are *not* reserved names. You can use them (even as a subprogram)
in a way completely unrelated to the standard definition. This is not
different from other languages that come with a standard library and where
you use a function with the same name as a function in the library.
As for Algol 60, specifying the year is cheating. You might as well say
that there are no different versions of C89.


Why is it cheating? Algol 68 is a completely different language. In
all the versions of Algol 60 the set of reserved names is identical
(it is empty).
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 14 '05 #10
Grumble wrote:
Richard Bos wrote:
.... snip ...
All of those, including your #define, are perfectly legal; the
implementation is to keep its paws off identifiers which are not
reserved for its use, of which local is one.


OK. What about

#define int const long
#define unsigned
#define extern static
#define double my_double
#define else

I imagine /they/ are explicitely forbidden?


Exactly. If you don't want the standard in pdf form, and want to
be able to use text utilities such as grep on it, download
N869.txt. Google for its location.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #11
CBFalconer wrote:
Grumble wrote:
What about

#define int const long
#define unsigned
#define extern static
#define double my_double
#define else

I imagine /they/ are explicitely forbidden?


Exactly. If you don't want the standard in pdf form, and want
to be able to use text utilities such as grep on it, download
N869.txt. Google for its location.


Thanks for the pointer ;-)

I skimmed section 6.10 (Preprocessing directives).
Am I looking in the right place?

--
Regards, Grumble
Nov 14 '05 #12
On Fri, 17 Dec 2004 00:57:52 GMT, in comp.lang.c , "Dik T. Winter"
<Di********@cwi.nl> wrote:
In article <mb********************************@4ax.com> Mark McIntyre <ma**********@spamcop.net> writes:
On Thu, 16 Dec 2004 13:24:51 GMT, in comp.lang.c ,
ga*****@yin.interaccess.com (Kenny McCormack) wrote:
But that does leave open this gap - which I find annoying - in C. Which is
that you can't ever really be sure what is reserved and what isn't


Show me a language in which this isn't the case.


Algol 60, Fortran.


And you can absolutely guatantee that NO future evolution of either
language will need to adopt new keywords.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
Nov 14 '05 #13
In article <13********************************@4ax.com> Mark McIntyre <ma**********@spamcop.net> writes:
On Fri, 17 Dec 2004 00:57:52 GMT, in comp.lang.c , "Dik T. Winter"
<Di********@cwi.nl> wrote:
In article <mb********************************@4ax.com> Mark McIntyre <ma**********@spamcop.net> writes:
On Thu, 16 Dec 2004 13:24:51 GMT, in comp.lang.c ,
ga*****@yin.interaccess.com (Kenny McCormack) wrote:

>But that does leave open this gap - which I find annoying - in C. Which is
>that you can't ever really be sure what is reserved and what isn't

Show me a language in which this isn't the case.
Algol 60, Fortran.


And you can absolutely guatantee that NO future evolution of either
language will need to adopt new keywords.


They will adopt new keywords, but they will *not* adopt new reserved words.
The reason is that both do no have reserved words. In Algol 60 in all its
variants keywords can be distinguished from other "words". In Fortran a
keyword is only recognised when it is in the correct syntactical position.
From an article I wrote back in 1996: I once wrote a Fortran program which
ended something like this:
IF(IF .EQ. EQ THEN) THEN
CALL CALL(END)
END IF
IF = PRINT
PRINT *, END
END
the stuttering program, every keyword was repeated with a different meaning,
and the actual version made some sense.


You may compile the above with a Fortran compiler and see it compiles (but
does not link, because the subroutine call is not provided).
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 14 '05 #14
On Fri, 17 Dec 2004 13:15:10 +0100, Grumble <de*****@kma.eu.org>
wrote:
CBFalconer wrote:
Grumble wrote:
What about

#define int const long
#define unsigned
#define extern static
#define double my_double
#define else

I imagine /they/ are explicitely forbidden?

Before/when you #include any standard header, which was the situation
you asked about upthread. Or at least you said the compiler's headers,
which might mean implementation-added ones rather than standard, but
implementation-added headers are already Undefined in the standard.

You can do this sort of nonsense strictly within your own code if you
want. You will be deservedly condemned and shunned by all sensible
people, and you will probably drive yourself crazy if you aren't
already, but you won't be violating the standard and it will work.
Exactly. If you don't want the standard in pdf form, and want
to be able to use text utilities such as grep on it, download
N869.txt. Google for its location.


Thanks for the pointer ;-)

I skimmed section 6.10 (Preprocessing directives).
Am I looking in the right place?


7.1.2p4.
- David.Thompson1 at worldnet.att.net
Nov 14 '05 #15
On Mon, 20 Dec 2004 06:29:07 +0000, Dave Thompson wrote:
On Fri, 17 Dec 2004 13:15:10 +0100, Grumble <de*****@kma.eu.org>
wrote:
CBFalconer wrote:
> Grumble wrote:
>
>> What about
>>
>> #define int const long
>> #define unsigned
>> #define extern static
>> #define double my_double
>> #define else
>>
>> I imagine /they/ are explicitely forbidden?
> Before/when you #include any standard header, which was the situation
you asked about upthread. Or at least you said the compiler's headers,
which might mean implementation-added ones rather than standard, but
implementation-added headers are already Undefined in the standard.

You can do this sort of nonsense strictly within your own code if you
want.
However you get undefined behaviour, at least I think so. C99 6.4.1p2 says

"The above tokens (case sensitive) are reserved (in translation phases 7
and 8) for use as keywords, and shall not be used otherwise."

The question is whether the "and shall not be used otherwise" restriction
is limited to translation phases 7 and 8. I don't think it can be because
if that was so there wouldn't be nothing to prevent the redefinition of
keywords before including standard headers.
You will be deservedly condemned and shunned by all sensible
people, and you will probably drive yourself crazy if you aren't
already, but you won't be violating the standard and it will work.


Of course it is great for IOCCC entries.
> Exactly. If you don't want the standard in pdf form, and want
> to be able to use text utilities such as grep on it, download
> N869.txt. Google for its location.


Thanks for the pointer ;-)

I skimmed section 6.10 (Preprocessing directives).
Am I looking in the right place?


7.1.2p4.


I don't see anything in 7.1.2 (or 7.1.3 for that matter) that prohibits
keywords being #defined prior to inclusion of standard headers. So unless
there's something else I missed we're left with 6.4.1.p2. And that doesn't
make any distinction about where the definition occurs; if #defining a
keyword is undefined it is undefined in all contexts.

Lawrence
Nov 14 '05 #16
On Tue, 21 Dec 2004 11:36:23 +0000, Lawrence Kirby
<lk****@netactive.co.uk> wrote:
On Mon, 20 Dec 2004 06:29:07 +0000, Dave Thompson wrote:

<snip: #define'ing keywords >
You can do this sort of nonsense strictly within your own code if you
want.


However you get undefined behaviour, at least I think so. C99 6.4.1p2 says

"The above tokens (case sensitive) are reserved (in translation phases 7
and 8) for use as keywords, and shall not be used otherwise."

The question is whether the "and shall not be used otherwise" restriction
is limited to translation phases 7 and 8. I don't think it can be because
if that was so there wouldn't be nothing to prevent the redefinition of
keywords before including standard headers.

Sorry, but I think it has to be limited to phase 7 & 8 because only
then are _tokens_ distinguished into keywords and identifiers; before
that you just have identifier(ish) pp-tokens. 6.4p3; 6.4.2.1p4.
You will be deservedly condemned and shunned by all sensible
people, and you will probably drive yourself crazy if you aren't
already, but you won't be violating the standard and it will work.


Of course it is great for IOCCC entries.

No comment on juxtaposing the concepts 'sensible' and 'IOCCC' :-)

<snip>
7.1.2p4.


I don't see anything in 7.1.2 (or 7.1.3 for that matter) that prohibits
keywords being #defined prior to inclusion of standard headers. So unless
there's something else I missed we're left with 6.4.1.p2. And that doesn't
make any distinction about where the definition occurs; if #defining a
keyword is undefined it is undefined in all contexts.

Last sentence of p4: The program shall not have any
macros with names lexically identical to keywords currently defined
prior to the
inclusion [of a standard header].

Formally 'prior' could be ambiguous, but I think it's clear this means
"immediately before the point of the source, as preprocessed so far,
where the #include directive occurs". (Given a suitable definition of
'preprocessed'.) It's not a constraint, so violating it is UB.

- David.Thompson1 at worldnet.att.net
Nov 14 '05 #17

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

Similar topics

28
by: JKop | last post by:
const unsigned short int AmountHumanAdultTeeth = 32; inline unsigned short int AddFive(unsigned short int Numbr) { return Numbr + 5; } USE THESE!!
1
by: Rafal 'Raf256' Maj | last post by:
Hi, is there a commend to undefine all macros #define inside a file? in example: #define FOR(x) for (..............) #define MyMacro1(x,y) ........... // ... code ...
13
by: jing | last post by:
hi all. i need to compile a sourcecode package in c++ download from an edu. site. here is what has happened #make all cd generate; make make: Entering directory `/home/dpr/generate' g++ -c -O3...
37
by: hasadh | last post by:
Hello, probably this may be a simple qn to u all but I need an answer plz. In my software i used macros like OK,TRUE,FALSE,FAILURE . A friend who included this code as a library into his module...
1
by: Michael Blackney | last post by:
I've been looking into cascaded macros and I can't seem to find if what I'm doing is portable. I want to do something like: #define THREE_ONES 1,1,1 #define ONE_TWO_THREE 1,2,3 #define...
35
by: Durgesh Sharma | last post by:
I want to use strrchar(source_string,last_char ) function from string.h header file,to find out the last occurrence of the NON SPACE Alphanumeric Character. Then i will put a NULL CHAR after...
6
by: vsnadagouda | last post by:
Hello All, For one of my applications I need to know what are all the predefined system/ compiler specific macros are. All these days I used to use "-v" or "-#" as a compiler option to figure...
15
by: spibou | last post by:
My understanding is that when you write a library then the header should be of the form #ifndef macro_corresponding_to_the_library #define macro_corresponding_to_the_library .. .. ...
9
by: pereges | last post by:
Ok, so once I'm done debugging my code(split across multiple modules) using the assert macro, I would want to switch off all the assert macros ued in the program. Does this mean I have to include:...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...

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.