C preprocessor

Christos Ricudis ricudis at komodino.itc.auth.gr
Wed Nov 3 10:53:38 EET 2010



On 11/03/10 10:10, Christos Houtouridis wrote:

>> #define fun(A,B)              \
>>    do{                        \
>>       A##.a = 5 + B##.a;      \
>>       A##.b = -5 + B##.b;     \
>>    }while (0)





#include <stdio.h>

typedef struct _aggouri {
        int mhkos;
        int diametros;
        int timh;
} aggouri_t;

typedef struct _poutsa {
        int mhkos;
        int diametros;
        int xrwma;
} poutsa_t;

#define enlarge(var,attribute,value)    \
   do{                                  \
        var.attribute += value;         \
   }while (0)

void main(void) {

        aggouri_t proion1;
        poutsa_t proion2;

        proion1.mhkos=32;
        proion2.mhkos=16;
        proion1.diametros=4;

        proion2.diametros=5;
        proion1.timh=58362;
        proion2.xrwma=0xFFFF00;


        enlarge(proion1,mhkos,5);
        enlarge(proion2,diametros,1);

        printf("p1.m=%d\n",proion1.mhkos);
        printf("p2.d=%d\n",proion2.diametros);
}


More information about the Linux-greek-users mailing list