Changes between Version 45 and Version 46 of ResumedC


Ignore:
Timestamp:
Sep 9, 2009, 10:36:45 PM (15 years ago)
Author:
Thanatermesis
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ResumedC

    v45 v46  
    492492
    493493
    494 
     494=== Macros ===
     495Remember to put always the parameters between parentheses, so that maybe the parameter needs to be calculated before to use it, just like:
     496{{{
     497#!C
     498#define MAX(a,b) ((a) > (b) ? (a) : (b))
     499
     500result = 2 * MAX( x, y & 0xFF );
     501}}}
     502
     503==== The # Operator ====
     504When used inside a macro, it is replaced by the parameter given to the macro call, so:
     505{{{
     506#!C
     507#define impr(i) printf( "value " #i " = %d", i)
     508
     509int x = 18, y = 2;
     510impr(x-y);
     511// result: "value x-y = 16"
     512}}}
     513
     514==== The ## Operator ====
     515When used inside a macro, it is replaced by the parameters given to the macro and removing spaces, so:
     516{{{
     517#!C
     518#define impr(i) printf( #var " with " #num " = %d" var ## num )
     519// var ## num (x and 5) is replaced by x5
     520
     521int x4 = 15, x5 = 16;
     522impr( x, 5 );
     523// result: "x with 5 = 16"
     524}}}
     525
     526
     527==== #include, #if, #else, #elif, #endif ====
     528{{{
     529#!C
     530#if VERSION == 1
     531   #define MY_PROJ "version1.h"
     532#else
     533   #define MY_PROJ "version2.h"
     534#endif
     535
     536#include MY_PROJ
     537}}}
     538
     539
     540==== #ifdef, #ifndef, #undef ====
     541{{{
     542#!C
     543#define MAX(a,b) ((a) > (b) ? (a) : (b))
     544
     545#ifdef MAX
     546#undef MAX
     547#endif
    495548
    496549