How to write macro for Notepad++?

Macros in Notepad++ are just a bunch of encoded operations: you start recording, operate on the buffer, perhaps activating menus, stop recording then play the macro. After investigation, I found out they are saved in the file shortcuts.xml in the Macros section. For example, I have there: <Macro name=”Trim Trailing and save” Ctrl=”no” Alt=”yes” Shift=”yes” … Read more

Is there a macro definition to check the Linux kernel version?

The linux/version.h file has a macro called KERNEL_VERSION which will let you check the version you want against the current linux headers version (LINUX_VERSION_CODE) installed. For example to check if the current Linux headers are for kernel v2.6.16 or earlier: #include <linux/version.h> #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,16) … #else … #endif A better way to get … Read more

How does Q_FOREACH (= foreach) macro work and why is it that complex?

The GCC version The GCC one is really quite simple. First of all it is used like this: Q_FOREACH(x, cont) { // do stuff } And that will be expanded to for (QForeachContainer<__typeof__(cont)> _container_(cont); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (x = *_container_.i;; __extension__ ({–_container_.brk; break;})) { // do stuff … Read more

Debug Print Macro in C?

I’ve seen this idiom a fair amount: #ifdef DEBUG # define DEBUG_PRINT(x) printf x #else # define DEBUG_PRINT(x) do {} while (0) #endif Use it like: DEBUG_PRINT((“var1: %d; var2: %d; str: %s\n”, var1, var2, str)); The extra parentheses are necessary, because some older C compilers don’t support var-args in macros.

Inline function v. Macro in C — What’s the Overhead (Memory/Speed)?

Calling an inline function may or may not generate a function call, which typically incurs a very small amount of overhead. The exact situations under which an inline function actually gets inlined vary depending on the compiler; most make a good-faith effort to inline small functions (at least when optimization is enabled), but there is … Read more

Where can I learn about constructing AST’s for Scala macros?

There isn’t a lot of documentation for the internals of the compiler available, but the things that are available should be enough to get started. Mirko Stocker, has written his Master Thesis about Scala Refactoring. In Appendix D (p. 95) he describes the architecture of the AST. It includes also a graphical overview: Another way … Read more

Macros for GCC/G++ to differentiate Linux and Mac OSX?

The next time you want to check out pre-defined macros supported by GCC on a platform, run the preprocessor with the flag -dM. It’ll list out all the predefined macros available on the system. For example: $ touch dummy.hxx $ cpp -dM ./dummy.hxx #define __DBL_MIN_EXP__ (-1021) #define __FLT_MIN__ 1.17549435e-38F #define __CHAR_BIT__ 8 #define __WCHAR_MAX__ 2147483647 … Read more

Can you capitalize a pasted token in a macro?

As far as I’m aware, the only operations that can be done on tokens in the C preprocessor (at least ISO/ANSI standard) is to replace, ‘stringify’ or concatenate them. I’m also unaware of any GCC or MSVC extensions that will let you do what you want. However, people have been coming up with clever (or … Read more

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