What is PRIu64 in C?

PRIu64 is a format specifier, introduced in C99, for printing uint64_t, where uint64_t is (from linked reference page): unsigned integer type with width of … 64 bits respectively (provided only if the implementation directly supports the type) PRIu64 is a string (literal), for example the following: printf(“%s\n”, PRIu64); prints llu on my machine. Adjacent string … Read more

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

Real-world use of X-Macros

I discovered X-macros a couple of years ago when I started making use of function pointers in my code. I am an embedded programmer and I use state machines frequently. Often I would write code like this: /* declare an enumeration of state codes */ enum{ STATE0, STATE1, STATE2, … , STATEX, NUM_STATES}; /* declare … Read more

Vim Macro on Every Line of Visual Selection

Suppose you had a macro q that ran (and remained) on a single line. Then you could run it on every line in your selection with: :'<,’>normal @q (if you already have a group of lines selected, hitting : produces :'<,’> on the command line) For example, the following macro capitalizes every word but the … Read more

How to define a string literal in gcc command line?

Two options. First, escape the quotation marks so the shell doesn’t eat them: gcc -Dname=\”Mary\” Or, if you really want -Dname=Mary, you can stringize it, though it’s a bit hacky. #include <stdio.h> #define STRINGIZE(x) #x #define STRINGIZE_VALUE_OF(x) STRINGIZE(x) int main(int argc, char *argv[]) { printf(“%s”, STRINGIZE_VALUE_OF(name)); } Note that STRINGIZE_VALUE_OF will happily evaluate down to … Read more

Jinja2 inline comments

Jinja2 has no support for comments within a {{ … }} statement. You can only use comments outside of such statements, and then only with {# .. #} or ## comment. {# .. #} is only meant for disabling part of a template or adding comments outside of other Jinja2 syntax. You can’t nest these. … Read more

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