我在C中很新,我想要做的是定義一個帶有常量地址的指針,這是我在testHeader.h中的嘗試:如何在C中定義全局常量字符指針並在整個文件中重新定義poiting值
char const *MY_VAR_P = (char * const)(0x4fffff);
extern char MYVAR;
然後在全球test.c的的(但我得到的是要重複使用在其他.c文件同一地址同一指針...):
#include "testHeader.h"
char MYVAR = '0';
*MY_VAR_P = MYVAR;
,這是錯誤:
test.c:33: warning: type defaults to `int' in declaration of `MY_VAR_P'
test.c:33: conflicting types for `MY_VAR_P'
test.h:2: previous declaration of `MY_VAR_P'
test.c:33: warning: initialization makes pointer from integer without a cast
test.c:33: initializer element is not constant
我真的不明白...請有人可以幫助我嗎?
謝謝!
改變爲'char * const的MY_VAR_P =(char * const的)(0x4fffff);'和'* MY_VAR_P = MYVAR;'移動到功能的內部。 – BLUEPIXY 2014-10-19 12:37:06