Functional programming in C with macro “Higher Order Function” generators
If you are on Linux/BSD Unix, take a look at queue(3) and check into /usr/include/sys/queue.h – it’s been done before 🙂
If you are on Linux/BSD Unix, take a look at queue(3) and check into /usr/include/sys/queue.h – it’s been done before 🙂
In Bash: HEADER=all_headers.h echo “#ifndef __ALL_HEADERS__” > $HEADER echo “#define __ALL_HEADERS__” >> $HEADER for file in dir/*.h do echo “#include <$file>” >> $HEADER done echo “#endif” >> $HEADER
Both expressions are false, so the code is never compiled. Here are potential explanations for why the programmer did not want to use the obvious #if 0 preprocessor directive to disable a section of code: the programmer did not want grep ‘#if 0’ to find his code snippet. the local coding conventions disallow #if 0 … Read more
I think it’s good to have a stringifying macro in your utils header: #define STR_IMPL_(x) #x //stringify argument #define STR(x) STR_IMPL_(x) //indirection to expand argument macros Then you can keep the macro numerical and stringify it on the spot: #define LEDS 48 int x = LEDS; void DrawFrame() { asm( “ldi R27, 0x00 \n\t” “ldi … Read more
Macros are replaced by the preprocessor by their value before your source file even compiles. There is no way you’d be able to change the value of the macro at runtime. If you could explain a little more about the goal you are trying to accomplish undoubtedly there is another way of solving your problem … Read more
In C, string literals are concatenated automatically. For example, const char * s1 = “foo” “bar”; const char * s2 = “foobar”; s1 and s2 are the same string. So, for your problem, the answer (without token pasting) is #ifdef __TESTING #define IV_DOMAIN “example.org” #elif __LIVE_TESTING #define IV_DOMAIN “test.example.com” #else #define IV_DOMAIN “example.com” #endif #define … Read more
The full error is error: expected unqualified-id before numeric constant note: in expansion of macro ‘homeid’ string homeid; ^ You’re trying to declare a variable with the same name as a macro, but that can’t be done. The preprocessor has already stomped over the program, turning that into string 1234;, which is not a valid … Read more
Yes, it is possible. The Doxygen documentation says: To document global objects (functions, typedefs, enum, macros, etc), you must document the file in which they are defined. In other words, there must at least be a /*! \file */ or a /** @file */ line in this file. You can use @defgroup, @addtogroup, and @ingroup … Read more
#define GENERATE_FUNCTION(Argument) void func_##Argument(){ … } More information here: http://en.wikipedia.org/wiki/C_preprocessor#Token_concatenation
Quote Wikipedia: Variable-argument macros were introduced in 1999 in the ISO/IEC 9899:1999 (C99) revision of the C language standard, and in 2011 in ISO/IEC 14882:2011 (C++11) revision of the C++ language standard. So it’s standard from C99 and C++11 onwards, but a GNU extension in C++03.