Created
January 20, 2016 19:07
-
-
Save mikhailramalho/42f992c4037e4e8babde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct { | |
_Bool is_float; | |
union { | |
float f; | |
double s; | |
}; | |
} mychoice_t; | |
double as_float(mychoice_t* ch) | |
{ | |
if (ch->is_float) return ch->f; | |
else return ch->s; | |
} | |
int main() | |
{ | |
mychoice_t t = {1, 2.0f}; | |
mychoice_t t1 = {0, 2.0f}; | |
double d = as_float(&t); | |
double d1 = as_float(&t1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment