Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      Fixed width integer types(since C++11)

      From cppreference.com
      <cpp‎ |types
       
       
      Utilities library
       
      Type support
      Basic types
      Fixed width integer types(C++11)
      Fixed width floating-point types(C++23)
      (C++11)    
      (C++17)
      Numeric limits
      C numeric limits interface
      Runtime type information
       

      Contents

      [edit]Types

      Defined in header<cstdint>
      int8_tint16_tint32_tint64_t
      (optional)
      signed integer type with width of exactly 8, 16, 32 and 64 bits respectively
      with no padding bits and using 2's complement for negative values
      (provided if and only if the implementation directly supports the type)
      (typedef)[edit]
      int_fast8_tint_fast16_tint_fast32_tint_fast64_t
      fastest signed integer type with width of at least 8, 16, 32 and 64 bits respectively
      (typedef)[edit]
      int_least8_tint_least16_tint_least32_tint_least64_t
      smallest signed integer type with width of at least 8, 16, 32 and 64 bits respectively
      (typedef)[edit]
      intmax_t
      maximum-width signed integer type
      (typedef)[edit]
      intptr_t
      (optional)
      signed integer type capable of holding a pointer tovoid
      (typedef)[edit]
      uint8_tuint16_tuint32_tuint64_t
      (optional)
      unsigned integer type with width of exactly 8, 16, 32 and 64 bits respectively
      (provided if and only if the implementation directly supports the type)
      (typedef)[edit]
      uint_fast8_tuint_fast16_tuint_fast32_tuint_fast64_t
      fastest unsigned integer type with width of at least 8, 16, 32 and 64 bits respectively
      (typedef)[edit]
      uint_least8_tuint_least16_tuint_least32_tuint_least64_t
      smallest unsigned integer type with width of at least 8, 16, 32 and 64 bits respectively
      (typedef)[edit]
      uintmax_t
      maximum-width unsigned integer type
      (typedef)[edit]
      uintptr_t
      (optional)
      unsigned integer type capable of holding a pointer tovoid
      (typedef)[edit]

      The implementation may define typedef namesintN_t,int_fastN_t,int_leastN_t,uintN_t,uint_fastN_t, anduint_leastN_t whenN is not 8, 16, 32 or 64. Typedef names of the formintN_t may only be defined if the implementation supports an integer type of that width with no padding. Thus,std::uint24_t denotes an unsigned integer type with a width of exactly 24 bits.

      Each of the macros listed in below is defined if and only if the implementation defines the corresponding typedef name. The macrosINTN_C andUINTN_C correspond to the typedef namesint_leastN_t anduint_leastN_t, respectively.

      [edit]Macro constants

      Defined in header<cstdint>
      Signed integers : minimum value
      INT8_MININT16_MININT32_MININT64_MIN
      (optional)
      minimum value ofstd::int8_t,std::int16_t,std::int32_t andstd::int64_t respectively
      (macro constant)[edit]
      INT_FAST8_MININT_FAST16_MININT_FAST32_MININT_FAST64_MIN
      minimum value ofstd::int_fast8_t,std::int_fast16_t,std::int_fast32_t andstd::int_fast64_t respectively
      (macro constant)[edit]
      INT_LEAST8_MININT_LEAST16_MININT_LEAST32_MININT_LEAST64_MIN
      minimum value ofstd::int_least8_t,std::int_least16_t,std::int_least32_t andstd::int_least64_t respectively
      (macro constant)[edit]
      INTPTR_MIN
      (optional)
      minimum value ofstd::intptr_t
      (macro constant)[edit]
      INTMAX_MIN
      minimum value ofstd::intmax_t
      (macro constant)[edit]
      Signed integers : maximum value
      INT8_MAXINT16_MAXINT32_MAXINT64_MAX
      (optional)
      maximum value ofstd::int8_t,std::int16_t,std::int32_t andstd::int64_t respectively
      (macro constant)[edit]
      INT_FAST8_MAXINT_FAST16_MAXINT_FAST32_MAXINT_FAST64_MAX
      maximum value ofstd::int_fast8_t,std::int_fast16_t,std::int_fast32_t andstd::int_fast64_t respectively
      (macro constant)[edit]
      INT_LEAST8_MAXINT_LEAST16_MAXINT_LEAST32_MAXINT_LEAST64_MAX
      maximum value ofstd::int_least8_t,std::int_least16_t,std::int_least32_t andstd::int_least64_t respectively
      (macro constant)[edit]
      INTPTR_MAX
      (optional)
      maximum value ofstd::intptr_t
      (macro constant)[edit]
      INTMAX_MAX
      maximum value ofstd::intmax_t
      (macro constant)[edit]
      Unsigned integers : maximum value
      UINT8_MAXUINT16_MAXUINT32_MAXUINT64_MAX
      (optional)
      maximum value ofstd::uint8_t,std::uint16_t,std::uint32_t andstd::uint64_t respectively
      (macro constant)[edit]
      UINT_FAST8_MAXUINT_FAST16_MAXUINT_FAST32_MAXUINT_FAST64_MAX
      maximum value ofstd::uint_fast8_t,std::uint_fast16_t,std::uint_fast32_t andstd::uint_fast64_t respectively
      (macro constant)[edit]
      UINT_LEAST8_MAXUINT_LEAST16_MAXUINT_LEAST32_MAXUINT_LEAST64_MAX
      maximum value ofstd::uint_least8_t,std::uint_least16_t,std::uint_least32_t andstd::uint_least64_t respectively
      (macro constant)[edit]
      UINTPTR_MAX
      (optional)
      maximum value ofstd::uintptr_t
      (macro constant)[edit]
      UINTMAX_MAX
      maximum value ofstd::uintmax_t
      (macro constant)[edit]

      [edit]Function macros for minimum-width integer constants

      INT8_CINT16_CINT32_CINT64_C
      expands to an integer constant expression having the value specified by its argument and whose type is thepromoted type ofstd::int_least8_t,std::int_least16_t,std::int_least32_t andstd::int_least64_t respectively
      (function macro)[edit]
      INTMAX_C
      expands to an integer constant expression having the value specified by its argument and the typestd::intmax_t
      (function macro)[edit]
      UINT8_CUINT16_CUINT32_CUINT64_C
      expands to an integer constant expression having the value specified by its argument and whose type is thepromoted type ofstd::uint_least8_t,std::uint_least16_t,std::uint_least32_t andstd::uint_least64_t respectively
      (function macro)[edit]
      UINTMAX_C
      expands to an integer constant expression having the value specified by its argument and the typestd::uintmax_t
      (function macro)[edit]
      #include <cstdint>UINT64_C(0x123)// expands to a literal of type uint_least64_t and value 0x123

      [edit]Format macro constants

      Defined in header<cinttypes>

      [edit]Format constants for thestd::fprintf family of functions

      Each of thePRI macros listed here is defined if and only if the implementation defines the corresponding typedef name.

      Equivalent
      forint or
      unsignedint
      DescriptionMacros for data types




      std::intx_t




      std::int_leastx_t
      std::int_fastx_t
      std::intmax_t
      std::intptr_t
      doutput of a signed decimal integer valuePRIdxPRIdLEASTxPRIdFASTxPRIdMAXPRIdPTR
      iPRIixPRIiLEASTxPRIiFASTxPRIiMAXPRIiPTR
      uoutput of an unsigned decimal integer valuePRIuxPRIuLEASTxPRIuFASTxPRIuMAXPRIuPTR
      ooutput of an unsigned octal integer valuePRIoxPRIoLEASTxPRIoFASTxPRIoMAXPRIoPTR
      xoutput of an unsigned lowercase hexadecimal integer valuePRIxxPRIxLEASTxPRIxFASTxPRIxMAXPRIxPTR
      Xoutput of an unsigned uppercase hexadecimal integer valuePRIXxPRIXLEASTxPRIXFASTxPRIXMAXPRIXPTR

      [edit]Format constants for thestd::fscanf family of functions

      Each of theSCN macros listed in here is defined if and only if the implementation defines the corresponding typedef name and has a suitablestd::fscanf length modifier for the type.

      Equivalent
      forint or
      unsignedint
      DescriptionMacros for data types




      std::intx_t




      std::int_leastx_t
      std::int_fastx_t
      std::intmax_t
      std::intptr_t
      dinput of a signed decimal integer valueSCNdxSCNdLEASTxSCNdFASTxSCNdMAXSCNdPTR
      iinput of a signed integer valueSCNixSCNiLEASTxSCNiFASTxSCNiMAXSCNiPTR
      uinput of an unsigned decimal integer valueSCNuxSCNuLEASTxSCNuFASTxSCNuMAXSCNuPTR
      oinput of an unsigned octal integer valueSCNoxSCNoLEASTxSCNoFASTxSCNoMAXSCNoPTR
      xinput of an unsigned hexadecimal integer valueSCNxxSCNxLEASTxSCNxFASTxSCNxMAXSCNxPTR

      [edit]Notes

      Because C++ interprets a character immediately following a string literal as auser-defined string literal, C code such asprintf("%"PRId64"\n",n); is invalid C++ and requires a space beforePRId64.

      The C99 standard suggests that C++ implementations should not define the above limit, constant, or format macros unless the macros__STDC_LIMIT_MACROS,__STDC_CONSTANT_MACROS or__STDC_FORMAT_MACROS (respectively) are defined before including the relevant C header (stdint.h orinttypes.h). This recommendation was not adopted by any C++ standard and was removed in C11. However, some implementations (such as glibc 2.17) try to apply this rule, and it may be necessary to define the__STDC macros; C++ compilers may try to work around this by automatically defining them in some circumstances.

      std::int8_t may besignedchar andstd::uint8_t may beunsignedchar, but neither can bechar regardless of its signedness (becausechar is not considered a "signed integer type" or "unsigned integer type").

      [edit]Example

      See also anote regarding spaces beforeformat macros used in this example.

      Run this code
      #include <cinttypes>#include <cstdio> int main(){std::printf("%zu\n", sizeof(std::int64_t));std::printf("%s\n", PRId64);std::printf("%+" PRId64"\n", INT64_MIN);std::printf("%+" PRId64"\n", INT64_MAX);     std::int64_t n=7;std::printf("%+" PRId64"\n", n);}

      Possible output:

      8lld-9223372036854775808+9223372036854775807+7

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2820C++11the requirements for optional typedef names and macros were inconsistent with Cmade consistent

      [edit]References

      • C++23 standard (ISO/IEC 14882:2024):
      • 17.4.1 Header <cstdint> synopsis [cstdint.syn]
      • 31.13.2 Header <cinttypes> synopsis [cinttypes.syn]
      • C++20 standard (ISO/IEC 14882:2020):
      • 17.4 Integer types [cstdint]
      • 29.12.2 Header <cinttypes> synopsis [cinttypes.syn]
      • C++17 standard (ISO/IEC 14882:2017):
      • 21.4 Integer types [cstdint]
      • 30.11.2 Header <cinttypes> synopsis [cinttypes.syn]
      • C++14 standard (ISO/IEC 14882:2014):
      • 18.4 Integer types [cstdint]
      • 27.9.2 C library files [c.files]
      • C++11 standard (ISO/IEC 14882:2011):
      • 18.4 Integer types [cstdint]
      • 27.9.2 C library files [c.files]

      [edit]See also

      C documentation forFixed width integer types
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/types/integer&oldid=169669"

      [8]ページ先頭

      ©2009-2025 Movatter.jp