Relative Content

Tag Archive for c++cmakec-preprocessorpreprocessorpreprocessor-directive

How to dynamically expand a variable in CPP

#include <iostream> using namespace std; const string getFileNameAsVarName(string filename, int lineNo) { string s = “”; for (char c : filename) { if (c > ‘a’ && c < ‘z’) { s += c; } } return s + to_string(lineNo); } #define DYNAMIC_NAME() (getFileNameAsVarName(__FILE__, __LINE__)) #define NAME() aaa int main() { int NAME() = 123; […]