名前空間
変種
操作

C++ キーワード: short

From cppreference.com
 
 
C++言語
全般
フロー制御
条件実行文
if
繰り返し文 (ループ)
for
範囲for (C++11)
ジャンプ文
関数
関数宣言
ラムダ式
inline指定子
動的例外仕様 (C++17まで*)
noexcept指定子 (C++11)
例外
名前空間
指定子
const/volatile
decltype (C++11)
auto (C++11)
constexpr (C++11)
consteval (C++20)
constinit (C++20)
記憶域期間指定子
初期化
代替表現
リテラル
ブーリアン - 整数 - 浮動小数点数
文字 - 文字列 - nullptr (C++11)
ユーザー定義 (C++11)
ユーティリティ
属性 (C++11)
typedef宣言
型エイリアス宣言 (C++11)
キャスト
メモリ確保
クラス
クラス固有の関数プロパティ
explicit (C++11)
static

特殊メンバ関数
テンプレート
その他
 
 

[編集] 使用法

[編集]

#include <climits>
#include <concepts>
#include <iostream>
#include <limits>
 
static_assert(sizeof(short) >= 16 / CHAR_BIT);
static_assert(sizeof(unsigned short) >= 16 / CHAR_BIT);
static_assert(std::numeric_limits<short>::min() <= -32'768); //'
static_assert(std::numeric_limits<short>::max() >= 32'767); //'
static_assert(std::numeric_limits<unsigned short>::max() >= 65'535u); //'
 
// concepts are available since C++20
static_assert(std::integral<short> and std::integral<unsigned short>);
 
template <typename T, typename... Ts>
concept all_same = (... and std::same_as <T, Ts>);
 
static_assert(all_same<short, short int, signed short, signed short int>);
static_assert(all_same<unsigned short, unsigned short int>);
 
#define OUT(...) std::cout << #__VA_ARGS__ << " = " << __VA_ARGS__ << '\n'
 
int main()
{
    OUT(sizeof(short));
    OUT(sizeof(unsigned short));
    OUT(std::numeric_limits<short>::min());
    OUT(std::numeric_limits<short>::max());
    OUT(std::numeric_limits<unsigned short>::max());
}
 
#undef OUT

実行結果の例

sizeof(short) = 2
sizeof(unsigned short) = 2
std::numeric_limits<short>::min() = -32768
std::numeric_limits<short>::max() = 32767
std::numeric_limits<unsigned short>::max() = 65535

[編集] 関連項目

English 日本語 中文(简体) 中文(繁體)