This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Feature suggestion: allow #ifdefs inside macro args


In article <3785F3A4.995E3ADC@hermes.si> you write:
>Martin Kahlert wrote:
>
>> Would it need a big effort to support #ifdefs inside macro args?
>>
>> The cpp's on HP, SUN an IRIX systems can cope with this,
>> gnu's cpp can not. Thus you cannot safely change any function
>> into a macro.
>
>I don't know what the standard says about pre-processing directives in macro
>arguments, but I have a very definite (and not very humble :-) opinion about
>which of the examples is more maintainable.

This isn't just a question of personal preferences for coding layout.
This can be a big problem with C libraries. e.g. glibc 2.1 now has macro
string functions, so someone doing:

strlen(
#ifdef foo
foo
#else
bar
#endif
);

will get a nasty surprise. glibc does allows you to turn this off at least.

ISO says in 6.8.3 (Macro replacement): "If there are sequences of
preprocessing tokens within the list of arguments that would otherwise
act as preprocessing directives, the behavior is undefined."

Admittedly it is not clear to me whether this is talking about the macro
definition, or the usage of the macro.

This is actually quite important, since if it is the latter that makes
what you are talking about strictly undefined; whereas if it is the former
it means the standard does not specify it, so we must assume the "normal"
rules will take effect.

Is there a language lawyer in the house?

Jifl
-- 
Cygnus Solutions, 35 Cambridge Place, Cambridge, UK.  Tel: +44 (1223) 728762
"I used to have an open mind but || Get yer free open source RTOS's here...
 my brains kept falling out."    || http://sourceware.cygnus.com/ecos
Help fight spam! http://spam.abuse.net/  These opinions are all my own fault


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]