c - Placing a preprocessor directive inside a string literal? -
i'm trying utilize #define define string literal (a filepath in case), cannot path #define'd element. in short, i'd this:
#define x /var/stuff #define y "x/stuff.txt" to give me y "/var/stuff/stuff.txt". possible do? beforehand.
edit: alternatively, concat 2 literals one?
#define x "/var/stuff" #define y x"/stuff.txt"
not way have it, no -- macro replacement not happen within string literals.
you can, however, paste string pieces:
#define str(x) #x #define expand(x) str(x) #define x /var/stuff #define y expand(x) "/stuff.txt" quick demo code this:
#include <iostream> int main(){ std::cout << y; } c gcc preprocessor
No comments:
Post a Comment