Error: macro names must be identifiers using #ifdef 0

The #ifdef directive is used to check if a preprocessor symbol is defined. The standard (C11 6.4.2 Identifiers) mandates that identifiers must not start with a digit: identifier: identifier-nondigit identifier identifier-nondigit identifier digit identifier-nondigit: nondigit universal-character-name other implementation-defined characters> nondigit: one of _ a b c d e f g h i j k l … Read more

How to test if preprocessor symbol is #define’d but has no value?

Soma macro magic: #define DO_EXPAND(VAL) VAL ## 1 #define EXPAND(VAL) DO_EXPAND(VAL) #if !defined(MYVARIABLE) || (EXPAND(MYVARIABLE) == 1) Only here if MYVARIABLE is not defined OR MYVARIABLE is the empty string #endif Note if you define MYVARIABLE on the command line the default value is 1: g++ -DMYVARIABLE <file> Here the value of MYVARIABLE is the … Read more

When can you omit the file extension in an #include directive?

The C++ standard headers do not have a “.h” suffix. I believe the reason is that there were many, different pre-standard implementations that the standard would break. So instead of requiring that vendors change their exiting “iostream.h” (for example) header to be standards compliant (which would break their existing user’s code), the standards committee decided … Read more

What are the valid characters for macro names?

Macro names should only consist of alphanumeric characters and underscores, i.e. ‘a-z’, ‘A-Z’, ‘0-9’, and ‘_’, and the first character should not be a digit. Some preprocessors also permit the dollar sign character ‘$’, but you shouldn’t use it; unfortunately I can’t quote the C standard since I don’t have a copy of it. From … Read more

C preprocessor: expand macro in a #warning

You can use the preprocessor directive #pragma message. Example: #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) #define AAA 123 #pragma message “content of AAA: ” STR(AAA) int main() { return 0; } The output may look like this: $ gcc test.c test.c:5:9: note: #pragma message: content of AAA: 123 #pragma message(“content of AAA: ” STR(AAA)) ^ … Read more

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