[PATCH][libcpp] Macros for unique named functions / identifiers

Rahul Kharche rahul@IceraSemi.com
Thu Apr 15 10:08:00 GMT 2010


>>You could require users of your macro to #define CANON_BASE_FILE
>>themselves.

The purpose of a canonical base file macro was to generate unique
function/identifier name across files/compilation units. Very
obviously there cannot be a single definition of this macro.
Files could be included into other files, so defining this per
file wouldn't work either. Modifying the make system to define
it might work, if push comes to shove.

>>Or you could just pick a name and make the objects static.

The only manner in which we could get the functions static is to
use nested functions, which we had grief with.

>> Can't you use __COUNTER__ for this?

COUNTER could be used at the risk of the user not re-defining it.

Rahul


-----Original Message-----
From: Tom Tromey [mailto:tromey@redhat.com] 
Sent: 13 April 2010 21:05
To: Rahul Kharche
Cc: GCC Patches; sdkteam-gnu
Subject: Re: [PATCH][libcpp] Macros for unique named functions /
identifiers

>>>>> "Rahul" == Rahul Kharche <rahul@IceraSemi.com> writes:

Rahul> The following patch adds macros CANON_BASE_FILE and CANON_LINE.

I'm sorry, but I don't think we want this in GCC.

Rahul> CANON_BASE_FILE is analogous to BASE_FILE, but not a string
Rahul> constant and only preserves characters valid as an identifiers.

I don't fully understand the need for this.

You could require users of your macro to #define CANON_BASE_FILE
themselves.  Or you could just pick a name and make the objects static.

I think those are both fairly typical approaches in existing code.
E.g., GCC uses the latter for vec.h.

Rahul> CANON_LINE is analogous to the line number and occurance count in
Rahul> the preprocessed output.

Can't you use __COUNTER__ for this?

Tom



More information about the Gcc-patches mailing list