0

I was reading opengl es book and in the source code i found this Macro

/// // Macros // #define ESUTIL_API #define ESCALLBACK 

later in the implementation file .c

void ESUTIL_API esInitContext ( ESContext *esContext ) { if ( esContext != NULL ) { memset( esContext, 0, sizeof( ESContext) ); } } 

from what I understand macros, they just replace what is defined by the macro.. although i don't understand what it is the point in this case.

Thanks.

2

4 Answers 4

3

This kind of macro is used to change the calling convention that is used by the compiler:

#define ESUTIL_API // nothing, use the standard calling convention 

or

#define ESUTIL_API __fastcall // use the fastcall calling convention 

The call type calling convention has usually to be put in a function definition between the return type and the function identifier name.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, so if we leaving it empty it will be stdcall? Great I understand now, Thank you ouah
You have to read the documentation of your compiler, but usually default is cdecl.
0

In this case is just a placeholder, in case one would ever need to add any decorations to the function declaration, more specifically, stuff like __declspec(dllexport), calling conventions or inlining requirements.

Comments

0

In this case ESUTIL_API macro can be replaced by the calling convention specification.

Comments

0

There may be some other place (or condition) where that macro is defined differently - for example a -D option to a compiler, or another block of code that is triggered by some other #defines. In that case you have to define at least an empty macro so that you can safely use it in a declaration like that and if the macro happens to be re-defined to a non-empty value - it will be used as such.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.