What is the NDEBUG preprocessor macro used for (on different platforms)?

The only ‘standard’ thing about NDEBUG is that it’s used to control whether the assert macro will expand into something that performs a check or not. MSVC helpfully defines this macro in release build configurations by defining it in the project for you. You can change that manually by editing the project configuration. Other toolchains … Read more

Is the backslash acceptable in C and C++ #include directives?

C99 says (§6.4.7/3): If the characters ‘, \, “, //, or /* occur in the sequence between the < and > delimiters, the behavior is undefined. Similarly, if the characters ‘, \, //, or /* occur in the sequence between the ” delimiters, the behavior is undefined. (footnote: Thus, sequences of characters that resemble escape … Read more

Which Cross Platform Preprocessor Defines? (__WIN32__ or __WIN32 or WIN32 )?

This article answers your question: C/C++ tip: How to detect the operating system type using compiler predefined macros (plus archive.org link in case it vanishes). The article is quite long, and includes tables that are hard to reproduce, but here’s the essence: You can detect Unix-style OS with: #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || … Read more

How to view C preprocessor output?

gcc -E file.c or g++ -E file.cpp will do this for you. The -E switch forces the compiler to stop after the preprocessing phase, spitting all it’s got at the moment to standard output. Note: Surely you must have some #include directives. The included files get preprocessed, too, so you might get lots of output. … Read more

Error: invalid operands of types ‘const char [35]’ and ‘const char [2]’ to binary ‘operator+’

Consider this: std::string str = “Hello ” + “world”; // bad! Both the rhs and the lhs for operator + are char*s. There is no definition of operator + that takes two char*s (in fact, the language doesn’t permit you to write one). As a result, on my compiler this produces a “cannot add two … Read more

What’s the difference between #if and #ifdef Objective-C preprocessor macro?

/#if works as usual if: #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { return YES; } #endif return NO; } /#ifdef means “if defined – some value or macros”: #ifdef RKL_APPEND_TO_ICU_FUNCTIONS #define RKL_ICU_FUNCTION_APPEND(x) _RKL_CONCAT(x, RKL_APPEND_TO_ICU_FUNCTIONS) #else // RKL_APPEND_TO_ICU_FUNCTIONS #define RKL_ICU_FUNCTION_APPEND(x) x #endif // RKL_APPEND_TO_ICU_FUNCTIONS or: #ifdef __OBJC__ #import <Foundation/Foundation.h> #endif Use this link for … Read more

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