Skip to content

Latest commit

 

History

History
76 lines (60 loc) · 2.24 KB

int_fast8_t.md

File metadata and controls

76 lines (60 loc) · 2.24 KB

int_fast8_t

  • cstdint[meta header]
  • std[meta namespace]
  • type-alias[meta id-type]
  • cpp11[meta cpp]
namespace std {
  using int_fast8_t = signed-integer-type;
}
  • signed-integer-type[italic]

概要

8ビット以上の、通常最も高速に処理される符号付き整数型。

int8_t型が環境によっては定義されないため、そのような状況でこの型を使用する。

#include <iostream>
#include <cstdint>
#include <type_traits>
#include <limits>

int main()
{
  // int_fast8_tの使用例
  std::int_fast8_t value = 42;
  
  // 値を出力
  std::cout << "value: " << static_cast<int>(value) << std::endl;
  
  // サイズを確認(処理系によって異なる可能性がある)
  std::cout << "size of int_fast8_t: " << sizeof(std::int_fast8_t) << " bytes" << std::endl;
  
  // 最小値と最大値
  std::cout << "minimum value: " << static_cast<int>(std::numeric_limits<std::int_fast8_t>::min()) << std::endl;
  std::cout << "maximum value: " << static_cast<int>(std::numeric_limits<std::int_fast8_t>::max()) << std::endl;
  
  // int8_tとの比較
  std::cout << "int_fast8_t is the same as int8_t: " 
            << std::is_same<std::int_fast8_t, std::int8_t>::value << std::endl;
            
  // 演算の例(オーバーフローに注意)
  std::int_fast8_t a = 100;
  std::int_fast8_t b = 50;
  std::int_fast8_t sum = a + b;  // 処理系によってはオーバーフローの可能性あり
  
  std::cout << "100 + 50 = " << static_cast<int>(sum) << std::endl;
  
  return 0;
}

出力例

value: 42
size of int_fast8_t: 1 bytes
minimum value: -128
maximum value: 127
int_fast8_t is the same as int8_t: 0
100 + 50 = -106

この出力例は特定の環境に依存しており、処理系によって異なる可能性があります。特に、int_fast8_tのサイズやオーバーフロー動作は処理系によって異なることがある。

バージョン

言語

  • C++11

処理系

  • Clang: 3.2 [mark verified]
  • GCC: 4.7.0 [mark verified]
  • ICC: ??
  • Visual C++: 2010 [mark verified], 2012 [mark verified], 2013 [mark verified]