Using #define to include another file in C++/C

后端 未结 4 1222
刺人心
刺人心 2020-12-15 20:57

I want to define a macro which includes another header file like so:

#define MY_MACRO (text) #include \"__FILE__##_inline.inl\"

So that whe

4条回答
  •  没有蜡笔的小新
    2020-12-15 20:58

    #if 0 /*Windows*/
    #define MKDIR_ENABLER 
    #define MY_MKDIR(x,y) _mkdir((x))
    #else /*Linux*/
    #define MKDIR_ENABLER 
    #define MY_MKDIR(x,y) mkdir((x),(y))
    #endif
    
    #include MKDIR_ENABLER
    
    int main(void)
    {
        MY_MKDIR("more_bla",0644);
        return 0;
    }
    

    This code includes the appropriate header file for mkdir (because it's different on UNIX and Windows) and introduces a nice wrapper for it.

提交回复
热议问题