check if uint64_t is defined

北城余情 提交于 2019-12-23 10:14:30

问题


The type uint64_t is not guaranteed to be defined on 32-bit platforms, and code like

int main() {
  uint64_t i = 0;
}

may result in compilation errors of the type incomplete type.

Is there a preprocessor directive to check if uint64_t is present? Any other way for checking if the type is defined?


回答1:


I think that reasonable approach is to check if associated macro UINT64_MAX is defined, e.g.

#include <cstdint> /* don't forget to include */

...

#ifdef UINT64_MAX
    ...
#endif

AFAIK you can't check directly if some type synonym is defined. According to C99, 7.18.2 Limits of specified-width integer types (don't have copy of C++ standard to confirm, emphasis mine):

The following object-like macros specify the minimum and maximum limits of the types declared in <stdint.h>. Each macro name corresponds to a similar type name in 7.18.1.



来源:https://stackoverflow.com/questions/24712091/check-if-uint64-t-is-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!