How, exactly, does the double-stringize trick work?

Yes, it’s guaranteed. It works because arguments to macros are themselves macro-expanded, except where the macro argument name appears in the macro body with the stringifier # or the token-paster ##. 6.10.3.1/1: … After the arguments for the invocation of a function-like macro have been identified, argument substitution takes place. A parameter in the replacement … Read more

Pragma in define macro

If you’re using c99 or c++0x there is the pragma operator, used as _Pragma(“argument”) which is equivalent to #pragma argument except it can be used in macros (see section 6.10.9 of the c99 standard, or 16.9 of the c++0x final committee draft) For example, #define STRINGIFY(a) #a #define DEFINE_DELETE_OBJECT(type) \ void delete_ ## type ## … Read more

How do you convert a jQuery object into a string?

I assume you’re asking for the full HTML string. If that’s the case, something like this will do the trick: $(‘<div>’).append($(‘#item-of-interest’).clone()).html(); This is explained in more depth here, but essentially you make a new node to wrap the item of interest, do the manipulations, remove it, and grab the HTML. If you’re just after a … Read more