UINT64_C

来源:互联网 发布:ims 层次数据库 编辑:程序博客网 时间:2024/06/18 10:14

如题,我们在使用Eclipse for C++时,通过增加定义-D__STDC_CONSTANT_MACROS, 可以使编译通过,但CDT的智能提示却总是报错, 通过一番查找,在stdint.h头文件中发现了它的定义:

[cpp] view plain copy
print?
  1. /* The ISO C99 standard specifies that in C++ implementations these 
  2.    should only be defined if explicitly requested.  */  
  3. #if !defined __cplusplus || defined __STDC_CONSTANT_MACROS  
  4.   
  5. /* Signed.  */  
  6. # define INT8_C(c)  c  
  7. # define INT16_C(c) c  
  8. # define INT32_C(c) c  
  9. # if __WORDSIZE == 64  
  10. #  define INT64_C(c)    c ## L  
  11. # else  
  12. #  define INT64_C(c)    c ## LL  
  13. # endif  
  14.   
  15. /* Unsigned.  */  
  16. # define UINT8_C(c) c  
  17. # define UINT16_C(c)    c  
  18. # define UINT32_C(c)    c ## U  
  19. # if __WORDSIZE == 64  
  20. #  define UINT64_C(c)   c ## UL  
  21. # else  
  22. #  define UINT64_C(c)   c ## ULL  
  23. # endif  
  24.   
  25. /* Maximal type.  */  
  26. # if __WORDSIZE == 64  
  27. #  define INTMAX_C(c)   c ## L  
  28. #  define UINTMAX_C(c)  c ## UL  
  29. # else  
  30. #  define INTMAX_C(c)   c ## LL  
  31. #  define UINTMAX_C(c)  c ## ULL  
  32. # endif  
  33.   
  34. #endif  /* C++ && constant macros */  

主要是这一句:
[cpp] view plain copy
print?
  1. #if !defined __cplusplus || defined __STDC_CONSTANT_MACROS  
由于我们的工程是c++的,第一个条件不满足, 第二个条件就是我们在编译时加入的宏定义,出现如题的错误肯定是这个宏定义了,但没有被智能识别程序识别。

解决方案:

1. 右键单击 c++ 工程,Properties>>C/C++ General>>Paths and Symbols>>Symbols>>GNU C++>>Add

2. 在弹出的对话框中输入Name:__STDC_CONSTANT_MACROS Values: 1

再到程序中按F3,是不是可以找到UINT64_C了?


通过此方法,你可以增加其它的宏,以供智能识别程序识别。

0 0
原创粉丝点击