Какой стандартный заголовок C ++ определяет SIZE_MAX?
blockquote>Предполагается, что он определен в
<cstdint>
, но его необязательный.Вот результаты по Fedora 22 с GCC 5.1:
#include <cstdint> // use SIZE_MAX
Результаты в:
g++ -DNDEBUG -g -O2 -fPIC -march=native -pipe -c filters.cpp In file included from /usr/include/c++/5.1.1/cstdint:35:0, from filters.cpp:14: /usr/include/c++/5.1.1/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. #error This file requires compiler and library support for the \ ^ filters.cpp: In constructor ‘Filter::Filter(BufferedTransformation*)’: filters.cpp:305:36: error: ‘SIZE_MAX’ was not declared in this scope : Filter(attachment), m_firstSize(SIZE_MAX), m_blockSize(0), m_lastSize(SIZE_M ^
Было просто проще сделать следующее и перестать беспокоиться о непереносной необязательности, которая все еще вызывает проблемы в 2015 году.
#include <limits> #ifndef SIZE_MAX # ifdef __SIZE_MAX__ # define SIZE_MAX __SIZE_MAX__ # else # define SIZE_MAX std::numeric_limits<size_t>::max() # endif #endif
Попытка
__SIZE_MAX__
возвращает вас к постоянной времени компиляции, которую вы, вероятно, жаждете. Вы можете увидеть, если он определен в препроцессоре сcpp -dM < /dev/null | grep __SIZE_MAX__
.(И как / почему
numeric_limits<size_t>::max()
является not , константа времени компиляции является еще одной загадкой C ++, но это другая проблема).