問題タブ [constant-expression]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - Is a glvalue integral constant expression a constant expression?
N4527 5.20 [expr.const]p3
An integral constant expression is an expression of integral or unscoped enumeration type, implicitly converted to a prvalue, where the converted expression is a core constant expression.
5.20 [expr.const]p5
A constant expression is either a glvalue core constant expression whose value refers to an entity that is a permitted result of a constant expression (as defined below), or a prvalue core constant expression whose value is an object where, for that object and its subobjects:
(5.1) — each non-static data member of reference type refers to an entity that is a permitted result of a constant expression, and
(5.2) — if the object or subobject is of pointer type, it contains the address of an object with static storage duration, the address past the end of such an object (5.7), the address of a function, or a null pointer value.
An entity is a permitted result of a constant expression if it is an object with static storage duration that is either not a temporary object or is a temporary object whose value satisfies the above constraints, or it is a function.
Question1: Is a
an integral constant expression?
Question2: Is a
a constant expression?
Question3: Is a glvalue integral constant expression a constant expression?
Question4:
If the answer of question 3 is yes, does this conflict with 5.20 p3 if the object has automatic storage duration?
c++ - `const int a = 1;` は `a` が定数式で、`a` に自動保存期間がある場合
N4527 5.20[expr.const]p2
条件式 e は、抽象マシン (1.9) の規則に従って e を評価した場合に、次の式のいずれかが評価されない限り、コア定数式です。
(2.7) — 適用されない限り、左辺値から右辺値への変換 (4.1)
(2.7.1) —定数式で初期化された、前に初期化された完全な不揮発性 const オブジェクトを参照する、整数型または列挙型の不揮発性 glvalue、または
(2.7.2) — 文字列リテラルのサブオブジェクトを参照する不揮発性の glvalue (2.13.5)、または
(2.7.3) — constexpr で定義された不揮発性オブジェクトを参照する、またはそのようなオブジェクトの可変でないサブオブジェクトを参照する、非揮発性の glvalue、または
(2.7.4) — 有効期間が e の評価内で始まる不揮発性オブジェクトを参照する、リテラル型の不揮発性 glvalue。
5.20[expr.const]p5
定数式は、値が定数式 (以下で定義) の許可された結果であるエンティティを参照する glvalue コア定数式、または値がオブジェクトである prvalue コア定数式のいずれかです。 :
— 参照型の各非静的データ メンバーは、定数式の許可された結果であるエンティティを参照します。
— オブジェクトまたはサブオブジェクトがポインター型の場合、静的ストレージ期間を持つオブジェクトのアドレス、そのようなオブジェクトの末尾を過ぎたアドレス (5.7)、関数のアドレス、または null ポインター値が含まれます。
エンティティは、それが一時オブジェクトではないか、値が上記の制約を満たす一時オブジェクトである静的ストレージ期間を持つオブジェクトである場合、または関数である場合、定数式の許可された結果です。
ではint b[a]{};
、a
は id 式、a
は左辺値コア定数式です。a
定数式ですか?
これは、Is a glvalue integer constant expression a constant expression?の明確化です。
c# - View を RelativeLayout の子 Xamarin Forms に挿入する
relativeLayout の children 配列にビュー obj を挿入する必要があります。しかし、問題は、どうすればそれができるかわからないため、親に相対的であることです。以下に示すように、追加したときのように
これを行う方法を知っている人はいますか?
いつもありがとうございます。
c++ - 定数式パラメータ
std::bitset
長さが定数関数パラメーターであるを作成する関数があります。定数が「整数定数式」ではないため、機能しません。これを機能させる方法はありますか?
参考のため:
c - -Os を使用してコンパイル時に GCC コンパイラに強制的に定数を計算させる方法
マクロを使用して、コンパイル時に定数 C 文字列のハッシュを計算しようとしました。それは私のコード例です:
ここで、GCCを実行してリストを表示します。
結果は予想どおりです。すべての文字列が削除され、そのハッシュに置き換えられました。しかし、通常は-Osを使用して組み込みアプリのコードをコンパイルします。やろうとすると、4文字未満の文字列のハッシュしかありません。また、パラメーターを設定してGCC 4.9max-unroll-times
を使用しようとしました:
その動作の理由と、この 4 文字の制限を拡張する方法がわかりません。
c++ - 「コア定数式」対「定数式」
コア定数式の定義は、N4140 の箇条書き (2.7.1) および (2.9.1) に見られるように、定数式の概念に依存します。
§5.19/2:
conditional-expression
e
は、抽象マシン (1.9) のルールに従って の評価が次の式のいずれかを評価しない限り、コア定数式です。e
...
(2.7.1) —定数式で初期化された、前に初期化された不揮発性 const オブジェクトを参照する整数型または列挙型の不揮発性 glvalue
...
(2.9.1) —定数式または
また、 N4140 の §5.19/4 に見られるように、定数式の定義はコア定数式の概念に依存します。
定数式は、値が静的記憶域期間を持つオブジェクトまたは関数を参照する glvalue コア定数式、またはそのオブジェクト とそのサブオブジェクトの場合、値がオブジェクトであるprvalue コア定数式のいずれか
です。
これは、数学的論理の基本原則に反しているようです。