Posts Tagged With 'define'

Written by Grigory Rechistov in Uncategorized on 20.05.2020. Tags: define, macrodefines,

Like to write multi-line #define macros but don’t like how the slashes \\ spoil their look? With the next simple trick of using /* C-style comments */, you can achieve the same thing in a beautiful manner.

#include <stdio.h>
#define PRINT_TWICE(x) do { /*
*/ printf( /*
*/ "%s %s\n", /*
*/ (x), (x) /*
*/ ); } while (0 …

Why bother

Macrodefinitions in C/C++ code are a sharp tool which must be wielded with care. Modern compilers allow us to write modern C code without resorting to the majority of preprocessor tricks we’ve had to use if we had been stuck in 1999. The goal here is …