Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::endian

      From cppreference.com
      <cpp‎ |types
       
       
      Utilities library
       
       
      Defined in header<bit>
      enumclass endian

      {
          little=/* implementation-defined */,
          big    =/* implementation-defined */,
          native=/* implementation-defined */,

      };
      (since C++20)

      Indicates theendianness of allscalar types:

      • If all scalar types are little-endian,std::endian::native equalsstd::endian::little.
      • If all scalar types are big-endian,std::endian::native equalsstd::endian::big.

      Corner case platforms are also supported:

      • If all scalar types havesizeof equal to1, endianness does not matter and all three values,std::endian::little,std::endian::big, andstd::endian::native are the same.
      • If the platform uses mixed endian,std::endian::native equals neitherstd::endian::big norstd::endian::little.

      Contents

      [edit]Possible implementation

      enumclass endian{#if defined(_MSC_VER) && !defined(__clang__)    little=0,    big=1,    native= little#else    little= __ORDER_LITTLE_ENDIAN__,    big= __ORDER_BIG_ENDIAN__,    native= __BYTE_ORDER__#endif};

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_endian201907L(C++20)std::endian

      [edit]Example

      Run this code
      #include <bit>#include <iostream> int main(){ifconstexpr(std::endian::native== std::endian::big)std::cout<<"big-endian\n";elseifconstexpr(std::endian::native== std::endian::little)std::cout<<"little-endian\n";elsestd::cout<<"mixed-endian\n";}

      Possible output:

      mixed-endian

      [edit]See also

      (C++23)
      reverses the bytes in the given integer value
      (function template)[edit]
      C documentation forendian
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/types/endian&oldid=178978"

      [8]ページ先頭

      ©2009-2025 Movatter.jp