I have this define in C header file:
define SOAP_STRINGIFY(s) #s
I'm not an experienced C programmer, but this seems https://gcc.gnu.org/onlinedocs/gcc-4.8.5/cpp/Stringification.html
c2nim fails to parse it. I've been trying with different #def in #C2NIM block, but I'm failing. How is this line supposed to be expanded?
Thanks
It just convert given expression to string literal.
And as it is a feature of preprocessor, an argument to the macro is not checked by C compiler unless the macro expand given argument.
#include <stdio.h>
#define STRINGIFY(x) #x
int main() {
printf(STRINGIFY(main(11+3+undefinedfunction("aaa"))));
printf("\n");
printf(STRINGIFY(∂±⇔));
return 0;
}
Output:
main(11+3+undefinedfunction("aaa"))
∂±⇔
{.emit: "#define STRINGIFY(x) #x".}
proc stringify(x: int): cstring {.importc: "STRINGIFY", nodecl.}
proc stringify(x: float): cstring {.importc: "STRINGIFY", nodecl.}
echo stringify(1 + 2)
var foo = 1
echo stringify(foo + 10)
echo stringify(123.0)
Output:
((NI) 3)
(NI)(TM__3gsRviFqqgOPGusKWyM6fw_2)
123.0
Macros like #define SOAP_STRINGIFY(s) #s is sometimes used for debugging or logging libraries internal code. If that macro was not used by any macros that you want to use in your Nim code, you can just ignore it.