我想以一种干净的方式保存变量的地址,所以没有编译器错误或警告。
我有这样的事情:保存变量的地址
unsigned int a = 5;
unsigned int address = (unsigned int)&a;
但我得到一些编译器警告。如果我写
unsigned int address = &a;
它也是错误的方式。那么干净的方式是什么(对于32位体系结构,无需在64位平台上运行),并且不使用标准库!
我想以一种干净的方式保存变量的地址,所以没有编译器错误或警告。
我有这样的事情:保存变量的地址
unsigned int a = 5;
unsigned int address = (unsigned int)&a;
但我得到一些编译器警告。如果我写
unsigned int address = &a;
它也是错误的方式。那么干净的方式是什么(对于32位体系结构,无需在64位平台上运行),并且不使用标准库!
您可以在C使用指针,它应该像
int *address = &a;
omg从我这是一个愚蠢的问题... :) – alabamajack 2014-10-31 08:13:36
@alabamajack这将是明智的问题可能的解决方案,然后再自动求助于SO ... – 2014-10-31 08:16:44
@TheParamagneticCroissant有时它的发生你没有前进 – alabamajack 2014-10-31 08:30:24
试试这个。
unsigned int a = 5;
unsigned int *address;
adress = &a;
'unsigned int * address =&a;' – 2014-10-31 08:11:09
你为什么要问?你为什么不使用指针?你会用这个地址做什么? – 2014-10-31 08:12:17
使用'uintptr_t' – BLUEPIXY 2014-10-31 08:15:37