I have a macro defined as following:
#define MAP_ACTUAL(input) do {\
char testPath[256];\
getcwd(testPath, sizeof(testPath));\
strcat(testPath, "/actual");\
strcat(testPath, input);\
input = testPath;\
} while(0)
And it works as intended when I use it once. When I use it twice in the same function like this:
static int do_rename(const char *from, const char *to) {
printf("[rename] %s -> %s\n", from, to);
MAP_ACTUAL(from);
MAP_ACTUAL(to);
// rest of the function
}
The values from
and to
point to the same address, I'm guessing to testPath
, resulting in both of them having the same value (not intended). I was under the impression that since macro was defined in a do while
scope it should use a separate address. How can I fix this?
I'm using gcc 8.2.1.