I've a tricky issue with a use of my macro. I specify the max length of a string parsed by sscanf with a macro define. Since I write all of my macro value between parenthesis (if it is a number) It should fix the operation problems (it's why we use parenthesis in general) but it creates an issue in my code :

#define xstr(s) str(s)
#define str(s) #s

#define VAL_MAX (5)
#define STRING_MAX (32)
// [...]

char out[STRING_MAX+1];
sscanf(&da->data[1], "%"xstr(STRING_MAX)"s", out)

which is converted by the pre-processor into :

sscanf(&da->data[1], "%(32)s", out)

So as you can see the parenthesis are in the code and this is the normal behavior. But sscanf doesn't seem to interpret the number in the parenthesis because it returns 0.
I really don't want to remove my parenthesis because it's safer this way. It's the only exception I've found in my code about this problem of parenthesizes. Is there any way to remove the parenthesis with a macro or to cancel them in the code ? I hope someone has a clue about how to fix it. :icon_wink: Thank you in advance.

I had to remove these parenthesizes and use a function to add them where I want to. Kinda solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.