1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| #include <stdio.h>
template<typename dst_type,typename src_type> dst_type pointer_cast(src_type src) { return *static_cast<dst_type*>(static_cast<void*>(&src)); }
int global_uninit_var; int global_init_var = 255; const int const_global_int = 255;
void func() { printf("Just a function\n"); } static void static_func() { } inline void inline_func() { }
typedef void (*pfunc_t)(); typedef int (*main_func_t)(); typedef void (*static_func_t)();
class Simple { public: static void Show() { printf("I am Show...\n"); } void localshow() { printf("I am localshow...\n"); } };
int main() { static int static_var = 255;
int local_uninit_var; int local_init_var = -1;
const int const_local_int = 127;
int* heap_int = new int();
pfunc_t pf = func; main_func_t mf = main; static_func_t sf = static_func; static_func_t csf = Simple::Show; void* cpf = pointer_cast<void*>(&Simple::localshow); pfunc_t ipf = inline_func;
printf("global_uninit_var: 0x%x\n", &global_uninit_var); printf("global_init_var: 0x%x\n", &global_init_var); printf("static_var: 0x%x\n", &static_var); printf("const_global_int: 0x%x\n", &const_global_int); printf("local_uninit_var: 0x%x\n", &local_uninit_var); printf("local_init_var: 0x%x\n", &local_init_var); printf("const_local_int: 0x%x\n", &const_local_int); printf("heap_int: 0x%x, 0x%x\n", &heap_int, heap_int); printf("point_func: 0x%x, 0x%x\n", &pf, pf); printf("point_main_func: 0x%x, 0x%x\n", &mf, mf); printf("static_func: 0x%x, 0x%x\n", &sf, sf); printf("class_static_func: 0x%x, 0x%x\n", &csf, csf); printf("class_local_func: 0x%x, 0x%x\n", &cpf, cpf); printf("inline_func: 0x%x, 0x%x\n", &ipf, ipf);
return 0; }
|