Home > Back-end >  How does #define work with function pointers?
How does #define work with function pointers?

Time:03-09

Please see the below code :

SomeStructure* SomeFunc();
#define kkData (*SomeFunc())

Question : What does kkData represents ?

EDIT : Removed semi-colon from second line.

CodePudding user response:

This directive

#define kkData (*SomeFunc());

means a call of the function SomeFunc and dereferencing the pointer to a structure returned from the function.

For example you could write in the program

SomeStructure s = kkData

Pay attention to that the semicolon in the directive should be removed. In this case the code in the program

SomeStructure s = kkData;

will be more clear.

CodePudding user response:

As with all #define directives kkData is simply text that will be replaced by (*SomeFunc()) before compilation. It is not by any means a function pointer, just a macro used to get a result from SomeFunc() and dereference it, in a single word.

  • Related