如题,我们在使用Eclipse for C++时,通过增加定义-D__STDC_CONSTANT_MACROS, 可以使编译通过,但CDT的智能提示却总是报错, 通过一番查找,在stdint.h头文件中发现了它的定义:
/* The ISO C99 standard specifies that in C++ implementations these
should only be defined if explicitly requested. */
#if !defined __cplusplus || defined __STDC_CONSTANT_MACROS
/* Signed. */
# define INT8_C(c) c
# define INT16_C(c) c
# define INT32_C(c) c
# if __WORDSIZE == 64
# define INT64_C(c) c ## L
# else
# define INT64_C(c) c ## LL
# endif
/* Unsigned. */
# define UINT8_C(c) c
# define UINT16_C(c) c
# define UINT32_C(c) c ## U
# if __WORDSIZE == 64
# define UINT64_C(c) c ## UL
# else
# define UINT64_C(c) c ## ULL
# endif
/* Maximal type. */
# if __WORDSIZE == 64
# define INTMAX_C(c) c ## L
# define UINTMAX_C(c) c ## UL
# else
# define INTMAX_C(c) c ## LL
# define UINTMAX_C(c) c ## ULL
# endif
#endif /* C++ && constant macros */
主要是这一句:
#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了?
通过此方法,你可以增加其它的宏,以供智能识别程序识别。