Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  C Macro Tips and Tricks

Preprocessor vs CompilerTo properly understand C macros, you must understand how a C program is compiled. In particular, you must understand the different things that happen in the preprocessor and in the compiler.The preprocessor runs first, as the name implies. It performs some simple textual manipulations, such as:Stripping comments. Resolving #include directives and replacing them with the contents of the included file. Evaluating #if and #ifdef directives. Evaluating #defines. Expading the macros found in the rest of the code according to those #defines.It is, of course, these...

18,286 0       C MACRO PREPROCESSOR TRICK


  Preprocessor magic:Default Arguments in C

This post is for programmers who like C or for one reason or another can't use anything else but C in one of their projects. The advantages of having default arguments is not something that needs convincing. It's just very nice and convenient to have them. C++ offers the ability to define them but C under the C99 standard has no way to allow it. In this post I will detail two ways I know of implementing default arguments in C. If a reader happens to know additional ways please share in the commentsSuppose we have a struct that contains some data and we want to initialize it//! The struct we wa...

12,203 0       C PREPROCESSOR DEFAULT ARGUMENTS


  C Preprocessor Hell

Lisp programmers should stop reading right now because they'll likely suffer severe injury of the jaw muscles as they laugh themselves silly at how hard it is to do some things in C. The C language has a pre-processor (typically called cpp) that is both infuriating and powerful. How powerful is usually best described as 'just too little' and it has happened more than once that I found myself almost - but not quite - able to do what I wanted to do.The frustration can run very deep at times like these. Recently I had another battle with the C pre-processor to write a set of macros to accompl...

5,666 0       C PREPROCESSOR LISP HELL