Communauté Informatique NDFR.net

Communauté Informatique NDFR.net (http://www.ndfr.net/forums/index.php)
-   Programmation (C/C++, Delphi, VB, etc.) (http://www.ndfr.net/forums/forumdisplay.php?f=64)
-   -   probleme de macro avec cast !!! argh !!!!! (http://www.ndfr.net/forums/showthread.php?t=2960)

toasty62 21-11-2003 10:52

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 ???

Benjy 21-11-2003 14:34

Re: probleme de macro avec cast !!! argh !!!!!
 
C'est sans doute une suggestion nulle, étant donné que ça fait 4 ans que je n'ai pas fait de C :

Code:

printf("float=%f\tint=%d\n", float GetIntFloat(paramFloat), int GetIntFloat(paramInt));


All times are GMT +2. The time now is 14:59.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.