Is there a way to "extend" the #define directive?

There are a lot of β€œdumb” ones in the project #define, and I want to remove them. Unfortunately, I cannot perform a simple search and replace, because the parameter is #defineparameterized. For instance:

#define FHEADGRP( x ) bool _process_grp##x( grp_id_t , unsigned char )

This is used to create the headers of several functions. I would like to somehow do the same thing as the preprocessor - to replace every macro call with its result (with the correct parameters entered. I hope you understand what I want to do.

I found out that with Visual Studio you can get pre-processed intermediate files with the / P switch. Unfortunately, this does not help me, because the file is "dirty" with thousands of other lines and with the extension #defines. I don’t want to do this, I just want to expand some macros and, preferably, do it in my IDE (which is Visual Studio). Is there any way to achieve this?

+3
source share
3 answers

Yes, there is - since you are using Visual Studio.

Visual Studio IDE . , , . . Ctrl - Shift - H . " " ": ".

FHEADGRP(*) bool _process_grp\1( grp_id_t , unsigned char )

*, \1 - .

[] , Search & Replace . . FHEADGRP(Foo) FHEADGRP( Foo ). C , Foo - .

- , FHEADGRP\(:b*(.*):b*\) bool _process_grp\0( grp_id_t , unsigned char ). , VS2005 ; , ? . .

+3

gcc -E ( , gcc, , ).

, #define . , , script ( Perl, , , ), .


Visual Studio /P . IDE .

+7

I would advise you to use sed, http://www.gnu.org/software/sed/ or some other regular expression tool.

0
source

Source: https://habr.com/ru/post/1750969/


All Articles