Construct path for #include directive with macro

后端 未结 4 864
耶瑟儿~
耶瑟儿~ 2020-11-27 07:54

I would like to have include file paths dynamically created by a macro for a target-configuration-dependent part of my program.

for example, I would like to construc

4条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 08:21

    From your description, it sound like you discovered that not every "" is a string. In particular, #include "corefoundation/header.h" looks like an ordinary string but it isn't. Grammatically, quoted text outside preprocessor directives are intended for the compiler, and compile to null terminated string literals. Quoted text in preprocessor directives is interpreted by the preprocessor in an implementation-defined way.

    That said, the error in your example is because Boost pasted the second and third token : / and filename. The first, fourth and fifth token (directory, . and h) are left unchanged. This is not what you wanted, obviously.

    It's a lot easier to rely on automatic string concatenation. "directory/" "filename" is the same string literal as "directory/filename" Note that there is no + between the two fragments.

提交回复
热议问题