When are C++ macros beneficial? [closed]

As wrappers for debug functions, to automatically pass things like __FILE__, __LINE__, etc: #ifdef ( DEBUG ) #define M_DebugLog( msg ) std::cout << __FILE__ << “:” << __LINE__ << “: ” << msg #else #define M_DebugLog( msg ) #endif Since C++20 the magic type std::source_location can however be used instead of __LINE__ and __FILE__ to … Read more

How to manually deprecate members

You can use the Available tag, for example : @available(*, deprecated) func myFunc() { // … } Where * is the platform (iOS, iOSApplicationExtension, macOS, watchOS, tvOS, * for all, etc.). You can also specify the version of the platform from which it was introduced, deprecated, obsoleted, renamed, and a message : @available(iOS, deprecated:6.0) func … Read more

How do I see a C/C++ source file after preprocessing in Visual Studio?

cl.exe, the command line interface to Microsoft Visual C++, has three different options for outputting the preprocessed file (hence the inconsistency in the previous responses about Visual C++): /E: preprocess to stdout (similar to GCC’s -E option) /P: preprocess to file /EP: preprocess to stdout without #line directives If you want to preprocess to a … Read more

Overloading Macro on Number of Arguments

Simple as: #define GET_MACRO(_1,_2,_3,NAME,…) NAME #define FOO(…) GET_MACRO(__VA_ARGS__, FOO3, FOO2)(__VA_ARGS__) So if you have these macros, they expand as described: FOO(World, !) // expands to FOO2(World, !) FOO(foo,bar,baz) // expands to FOO3(foo,bar,baz) If you want a fourth one: #define GET_MACRO(_1,_2,_3,_4,NAME,…) NAME #define FOO(…) GET_MACRO(__VA_ARGS__, FOO4, FOO3, FOO2)(__VA_ARGS__) FOO(a,b,c,d) // expands to FOO4(a,b,c,d) Naturally, if you … Read more

#define macro for debug printing in C?

If you use a C99 or later compiler #define debug_print(fmt, …) \ do { if (DEBUG) fprintf(stderr, fmt, __VA_ARGS__); } while (0) It assumes you are using C99 (the variable argument list notation is not supported in earlier versions). The do { … } while (0) idiom ensures that the code acts like a statement … Read more

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