View Single Post
  #1  
Old 21-11-2003, 10:52
toasty62 toasty62 is offline
Membre junior
 
Join Date: 21-11-2003
Posts: 1
Exclamation probleme de macro avec cast !!! argh !!!!!

g un big pb ac une macro et je c pa trop d'ou ca vient... doit y avoir un pb de cast ou de pointeur...
voila le code :

typedef struct
{
char type;

union
{
float type0;
int type1;
};

} param;


#define GetIntFloat(variable) variable.type==0 ? variable.type0 : variable.type1


int main(int argc, char* argv[])
{
// pour les float
param paramFloat;
paramFloat.type = 0;
paramFloat.type0 = 123.4;

float f = GetIntFloat(paramFloat);

// pour les int
param paramInt;
paramInt.type = 1;
paramInt.type1 = 123;

int i = GetIntFloat(paramInt);

printf("float=%f\tint=%d\n", f,i);

system("pause");
return 0;
}

jusque là, ce code marche, mais si maintenant je change le printf par :
printf("float=%f\tint=%d\n", GetIntFloat(paramFloat), GetIntFloat(paramInt));

eh ben ca marche pu !
prtant au dessus le GetIntFloat retourne bien un float ou un int selon ce qui a ét décidé... ac ce printf, le GetIntFloat ne marche pas pr le INT...
snif... qqun pourrait-il m'aider svp ???
Reply With Quote