samedi 24 août 2019

How to define block of code inside if condition

I work with old C project and should make there several changes It has lots of macros.... The function calls are defined there as

#define myFunc(arg) myBaseFunc(arg)

bool myBaseFunc is a function, actually there are several myBaseFunc (its a kind of polymorphism) I need to add some check of arguments correctness to myFunc Actually the project has :

#define checkArg(arg) {\
 // lot of code
}

I can`t change checkArg implementation 1) I thought to //

/*It is not correct if I do `if(myFunc(arg))`*/

#define myFunc(arg)\
checkArg(arg)\
myBaseFunc(arg)

2)I thought to

/*It is better...but compiler doesn`t like code block `{}` inside`if(myFunc(arg))`*/

#define myFunc(arg)(\
checkArg(arg),\
myBaseFunc(arg))

Is there a workaround for this case

Aucun commentaire:

Enregistrer un commentaire