Getting a structural type with an anonymous class’s methods from a macro

This question is answered in duplicate by Travis here. There are links to the issue in the tracker and to Eugene’s discussion (in the comments and mailing list). In the famous “Skylla and Charybdis” section of the type checker, our hero decides what shall escape dark anonymity and see the light as a member of … Read more

What does “#pragma comment” mean?

#pragma comment is a compiler directive which indicates Visual C++ to leave a comment in the generated object file. The comment can then be read by the linker when it processes object files. #pragma comment(lib, libname) tells the linker to add the ‘libname’ library to the list of library dependencies, as if you had added … Read more

Saving vim macros

Use q followed by a letter (for example ‘x’) to record a macro, then press q to end the macro definition. The pattern surrounded by the starting and ending ‘q’ during this definition just goes into one of the copy/paste registers (in this case, register ‘x’) so you can paste it with the”xp or “xP … Read more

__FILE__ macro shows full path

Try #include <string.h> #define __FILENAME__ (strrchr(__FILE__, “https://stackoverflow.com/”) ? strrchr(__FILE__, “https://stackoverflow.com/”) + 1 : __FILE__) For Windows use ‘\\’ instead of “https://stackoverflow.com/”.

C multi-line macro: do/while(0) vs scope block [duplicate]

Andrey Tarasevich provides the following explanation: On Google Groups On bytes.com [Minor changes to formatting made. Parenthetical annotations added in square brackets []]. The whole idea of using ‘do/while’ version is to make a macro which will expand into a regular statement, not into a compound statement. This is done in order to make the … 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

Strange definitions of TRUE and FALSE macros

Let’s see: “https://stackoverflow.com/” / “https://stackoverflow.com/” means the char literal /, divided by the char literal “https://stackoverflow.com/” itself. The result is one, which sounds reasonable for TRUE. And ‘-‘ – ‘-‘ means the char literal ‘-‘, subtracted from itself. This is zero (FALSE). There are two problems with this: first, it’s not readable. Using 1 and … Read more

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