Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#define with space

Is it possible to write define with spaces such as:

#define replace to replacement here

I want to replace "replace to" with "replacement here".

EDIT:

I want to test private members:

I did write

#define private public

but it didn't work for private slots in Qt

so my intend was to use something like

#define private slots: public slots:

anyway I have found another way to test slots and by the way I'm aware of that this is an ugly hack.

like image 329
Rob Ashton Avatar asked Mar 04 '11 12:03

Rob Ashton


4 Answers

no, you can't

#define identifier something

what you define must be an identifier which cannot contain space. Nor can it contain hyphen, begin with a number, etc. you can define only an identifier

what you wrote will work

#define replace to replacement here

but not as you expect. This line defined replace to be substituted with to replacement here

like image 141
Armen Tsirunyan Avatar answered Nov 04 '22 04:11

Armen Tsirunyan


You could do...

#define replace replacement
#define to here

Watch out for unintended side effects of the defines. You would probably want to #undef them after they've done their job.

like image 4
Martin Stone Avatar answered Nov 04 '22 04:11

Martin Stone


If you are doing unit test, you can compile your file with the following flag

-Dprivate=public

Then in your unit test, you will be able to call every private method of your class.

EDIT:

I've recently remarked that using the -fno-access-control flag on gcc compiler allows you to access private method or member. More info on that topic can be found here: Unit testing with -fno-access-control

like image 3
L. Carlier Avatar answered Nov 04 '22 04:11

L. Carlier


No, that's not possible. Why not just do this instead:

#define replace_to replacement here
like image 2
Axel Avatar answered Nov 04 '22 05:11

Axel