Is it possible create a "variable" header guard name in C? -


fellow programmers,

i'm new c preprocessor , have been trying create generic-like library in c (as exercise), , i've come upon little problem when creating header guards.

all preprocessor macros set can include , use headers this:

#define type int #include "myheader.h" #undef type  #define type float #include "myheader.h" #undef type  int main(void){     //do stuff     myfunc_int();      //more stuff     myfunc_float();      return 0; } 

but problem appears when need include headers in more 1 file. header guards applied in case, since header can included once -for each type-, neither usual construction nor #pragma once can used.

my question is: possible create "variable" header guard work different type definitions?

when want include header various compilation units, divide header publich part plays role of header , private part plays role of *.c file, example:

#define m_concat(a, b) a##b  type m_concat(type, _min)(type a, type b);  #ifdef implement  type m_concat(type, _min)(type a, type b) {     return (a < b) ? : b; }  #endif /* implement */ 

then can include header multiple files, have make sure 1 file defines implement before including header:

#define implement    // in 1 file  #define type float #include "myheader.h" #undef type  #define type int #include "myheader.h" #undef type 

this file separate compilation unit, myheader.c. must take care implement function types, however. (but linker tell you, types you've missed.)


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

android - MPAndroidChart - How to add Annotations or images to the chart -