C Preprocessor, Stringify the result of a macro

Like this: #include <stdio.h> #define QUOTE(str) #str #define EXPAND_AND_QUOTE(str) QUOTE(str) #define TEST thisisatest #define TESTE EXPAND_AND_QUOTE(TEST) int main() { printf(TESTE); } The reason is that when macro arguments are substituted into the macro body, they are expanded unless they appear with the # or ## preprocessor operators in that macro. So, str (with value TEST … Read more

Why aren’t there macros in C#?

from the C# faq. http://blogs.msdn.com/CSharpFAQ/archive/2004/03/09/86979.aspx Why doesn’t C# support #define macros? In C++, I can define a macro such as: #define PRODUCT(x, y, z) x * y * z and then use it in code: int a = PRODUCT(3, 2, 1); C# doesn’t allow you to do this. Why? There are a few reasons why. … Read more

C/C++, can you #include a file into a string literal? [duplicate]

The C/C++ preprocessor acts in units of tokens, and a string literal is a single token. As such, you can’t intervene in the middle of a string literal like that. You could preprocess script.py into something like: “some code\n” “some more code that will be appended\n” and #include that, however. Or you can use xxd​ … Read more

Is there a preprocessor directive for detecting C++11x support? [duplicate]

__cplusplus should be defined as 199711L in pre-C++11 compilers, 201103L in those suporting C++11. Whether this is much help in practice is another question: most compilers are only halfway there, so shouldn’t be defining it as 201103L, even if they support the features you are interested in. And it’s not unheard of for a compiler … Read more

# and ## in macros

An occurrence of a parameter in a function-like macro, unless it is the operand of # or ##, is expanded before substituting it and rescanning the whole for further expansion. Because g‘s parameter is the operand of #, the argument is not expanded but instead immediately stringified (“f(1,2)”). Because h‘s parameter is not the operand … Read more

Why does this .c file #include itself?

The file includes itself so the same source code can be used to generate 4 different sets of functions for specific values of the macro USIZE. The #include directives are actually enclosed in an #ifndef, which limits the recursion to a single level: #ifndef USIZE // common definitions … // #define VSENC vsenc #define VSDEC … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)