Skip to content

Instantly share code, notes, and snippets.

@yoya
Last active December 17, 2015 18:09
Show Gist options
  • Save yoya/5651633 to your computer and use it in GitHub Desktop.
Save yoya/5651633 to your computer and use it in GitHub Desktop.
double => long cast
#include <stdio.h>
int main(void) {
double d = 1234567890;
double *dp = &d;
long l = (double) d;
long *lp = (long *) dp;
union dl_t {
double d;
long l;
} dl;
dl.d = d;
printf("d:%f dp:%f\n", d, *dp);
printf("l:%ld lp:%ld dl.l=%ld\n", l, *lp, dl.l);
return 0;
}
/* outout
d:1234567890.000000 dp:1234567890.000000
l:1234567890 lp:4742964961033060352 dl.l=4742964961033060352
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment