Skip to content

Instantly share code, notes, and snippets.

@cpuwolf
Last active December 29, 2021 23:00
Show Gist options
  • Save cpuwolf/002e92067543593ad9d28948dbc8aa7a to your computer and use it in GitHub Desktop.
Save cpuwolf/002e92067543593ad9d28948dbc8aa7a to your computer and use it in GitHub Desktop.
//
// main.cpp
// fdouble
//
// Created by wshuai on 2021/12/29.
//
#include <stdio.h>
void * store[3];
void convert(float a, double b)
{
store[0] = *(void**)&a;
store[1] = *(void**)&b;
}
int main(int argc, const char * argv[]) {
// insert code here...
float arg1=29.88;
double arg2=29.88;
float arg3;
store[0]=0;
store[1]=0;
convert(arg1, arg2);
printf("%p\n", store[0]);
printf("%p\n", store[1]);
printf("%f\n", *(float *)(store+0));
printf("%f\n", *(float *)(store+1));
printf("%f\n", *(double *)(store+1));
arg3 = *(double *)(store+1);
printf("%f\n", arg3);
store[2] = *(void**)&arg3;
printf("%p\n", store[2]);
printf("%f\n", *(float *)(store+2));
printf("%f\n", *(double *)(store+2));
return 0;
}
//MACOS X-code
/*
0xefbff47041ef0a3d
0x403de147ae147ae1
29.879999
-0.000000
29.880000
29.879999
0xae147ae141ef0a3d
29.879999
-0.000000
*/
//MSVC2017 x64
/*
0000000141EF0A3D
403DE147AE147AE1
29.879999
-0.000000
29.880000
29.879999
CCCCCCCC41EF0A3D
29.879999
-92559604747829222126337803568271202203659446267699534005010432.000000
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment