preprocessor, token concatenation, no valid preprocessor token

C

Cronus

Hi

the following code the g++ (g++ (GCC) 3.3.3 (Debian 20040422)) emits the
error message that pasting of :: and hello is no valid preprocessor token.
The g++ 2.95.3 accepts the code. I know that handling of the ##
preprocessing operator has changed.

How I have to change the macro definiton of A(P)?
NO changes at macro calling should be necessary!

Thanks in advance!



#define A(P)    int P##hello(void) {return 1;}

class B {
public:
        B() {
                b = 1;
        }

        private:
                        int b;
                        int hello();
};

A(D40);
A(B::);

int main(void)  {
}
 
P

Paul Mensonides

Cronus said:
Hi

the following code the g++ (g++ (GCC) 3.3.3 (Debian 20040422)) emits
the error message that pasting of :: and hello is no valid
preprocessor token. The g++ 2.95.3 accepts the code. I know that
handling of the ## preprocessing operator has changed.

How I have to change the macro definiton of A(P)?
NO changes at macro calling should be necessary!

In general, it is not possible to do this. Pasting '::' to 'hello' is undefined
behavior, and you can't make an identifier out of two other identifiers without
token-pasting. Instead, you should get rid of the concatenation and pass the
entire name:

#define A(id) int id(void) {return 1;}

A(D40hello)
A(B::hello)

Further, it is extremely likely that there is a better way to do whatever it is
you're doing (such as tag dispatch + ADL).

Regards,
Paul Mensonides
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top