FBIagent
Erfahrenes Mitglied
Du könntest das was Beichtpfarrer gezeigt hat verwenden, so etwas
, was ich sehr unschön finde, aber du könntest auch mit einem flag in deinen
Funktionen arbeiten:
Ich bin mir jetzt nicht sicher ob switch/case zum C Standard gehört.
Best wishes
FBIagent
C:
#ifndef __MYSTRUCT_H__
#define __MYSTRUCT_H__
typedef struct {
int MyInt;
float MyFloat;
} MYSTRUCT;
#define REG_MYSTRUCT_SETPARAM( T, P ) void MyStruct_SetParam( MYSTRUCT &Struct, T Val ) { \
Struct.P = Val; \
}
#define REG_MYSTRUCT_MUL( T, P ) void MyStruct_Mul( MYSTRUCT &Struct, T Val ) { \
Struct.P *= Val; \
}
#define REG_MYSTRUCT_FUNCTIONS( T, P ) REG_MYSTRUCT_SETPARAM( T, P ) \
REG_MYSTRUCT_MUL( T, P )
REG_MYSTRUCT_FUNCTIONS( int, MyInt )
REG_MYSTRUCT_FUNCTIONS( float, MyFloat )
#endif
Funktionen arbeiten:
C:
enum MyStruct_Type {
MYINT,
MYFLOAT
};
void MyStruct_SetParam( MYSTRUCT &Struct, void *Val, MyStruct_Type TypeFlag ) {
switch ( TypeFlag ) {
case MYINT:
Struct.MyInt = ( int )Val;
break;
case MYFLOAT:
Struct.MyFloat = ( float )Val;
break;
default;
/* Nö? */
break;
}
}
Ich bin mir jetzt nicht sicher ob switch/case zum C Standard gehört.
Best wishes
FBIagent