Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#define line of code to something else

Tags:

c++

c

Is it at all possible in c/c++ to do something like to following:

#define (_asm int 3;) (exit(1))

So that everywhere in my code this line will be replaced at compile time. I know this is bad practice but is it possible.

cheers

like image 369
B_o_b Avatar asked Dec 27 '22 13:12

B_o_b


1 Answers

You could do a global search and replace with your programming editor (or IDE) of choice and change _asm int 3 to e.g. FOO, and then define a macro FOO like this:

#if 1 // <<<- change this test to determine how `FOO` is expanded
  #define FOO _asm int 3
#else
  #define FOO exit(1)
#endif
like image 104
Paul R Avatar answered Jan 08 '23 17:01

Paul R