Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to do a #define inside of another #define?

I know that I am trying to shoot myself in the leg ;) However, it will allow me to make the rest (big amount) of code smaller and more readable.

Is there any tricky way to create preprocessor macro inside of another preprocessor macro?

Here is the example, what I am looking for. My real scenario is more complex

// That's what I want to do and surely C++ doesn't like it. #define MACROCREATER(B) #define MACRO##B B+B  void foo() {  MACROCREATOR(5) // This should create new macro (#define MACRO5 5+5)   int a = MACRO5; // this will use new macro } 
like image 641
Victor Ronin Avatar asked Jul 22 '10 22:07

Victor Ronin


People also ask

What are V up?

What is a V-Up? The V-Up is a full-body move that works your core, legs, back and shoulders. The exercise is beloved by fitness fanatics for its ability to work the upper and lower abdominal muscles simultaneously. A V-Up involves sitting on the floor or a mat and positioning the body in the shape of the letter “V.”


2 Answers

The C++ Standard says (16.3.4.3):

The resulting completely macro-replaced preprocessing token sequence [... of the macro expansion...] is not processed as a preprocessing directive even if it resembles one...

So no, there is no 'official' way of achieving what you want with macros.

like image 124
hkaiser Avatar answered Sep 18 '22 15:09

hkaiser


No. Even if a macro expands into something that looks like a preprocessing directive, the expansion is not evaluated as a preprocessing directive.

like image 32
James McNellis Avatar answered Sep 20 '22 15:09

James McNellis