LoginSignup
0
0

3. Terms, definitions, and symbols CN3054:2022 (1) p3.c

Last updated at Posted at 2022-10-11

はじめに(Introduction)

N3054 Working Draft, Standard for Programming Language C

http://www.open-std.org/jtc1/sc22/wg14/docs/papers/2022/n3054.pdf

CN3054は、ISO/IEC JTC1 SC22 WG14の作業原案(Working Draft)です。
公式のISO/IEC 9899原本ではありません。

ISO/IEC JTC1 SC22 のWG14を含むいくつかのWGでは、可能な限り作業文書を公開し、幅広い意見を求めています。

ISO/IEC JTC1 SC7からISO/IEC JTC1 SC22リエゾンとして、2000年頃、C/C++の品質向上に貢献しようとした活動をしていたことがあります。その頃は、まだISO/IEC TS 17961の原案が出る前です。Cの精神が優勢で、セキュリティ対策は補助的な位置付けでした。ISO/IEC TS 17961の制定と、C/C++のライブラリ類の見直しと、C++の進化はどんどん進んでいきます。 

進化の具合が、どちらに行こうとしているかは、コンパイルて実行させてみないとわかりません。C/C++の規格案の電子ファイルは、そのままコンパイルできる形式であるとよいと主張してきました。MISRA-C/C++, CERTC/C++でも同様です。MISRA-C/C++は、Example Suiteという形で、コード断片をコンパイルできる形で提供するようになりました。

一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(gcc, clang)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C/C++, MISRA C/C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, 箱庭プロジェクト、g++(GCC), clang++(LLVM)との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。

最新規格はCN4950

背景(back ground)

C/C++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに1回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。

過去に何度か、自分のネットでの記録に助けられたことがあります。

また
https://researchmap.jp/joub9b3my-1797580/#_1797580
に記載したサイトのお世話になっています。

作業方針(sequence)

clangでは--std=c11, -std=c17 -std=c2xの3種類
gccでは-std=c11, -std=c17 -std=c2xの3種類
でコンパイルし、

1)コンパイルエラーを収集する。
2)コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
3)リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
4)意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。

1)だけのものから4)まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。

bash
$ docker run -v /Users/ogawakiyoshi/n4910/n3540:/Users/ogawakiyoshi/n4910/n3540 -it kaizenjapan/n3540 /bin/bash

読書感想文

CコンパイラによるC言語規格の読書感想文として掲載しています。

コンパイル実験が、CN3242に対する、gccとclangによる感想文だということご理解いただけると幸いです。

読書感想文は人間かAIだけが作るものとは限りません。
本(電子書籍を含む)を入力として、その内容に対する文字列を読書感想文として受け止めましょう。
元の文章をあり方、コンパイルできるように電子化しておくこと、コンパイラが解釈可能な断片の作り方など。

個人開発

Cコンパイラの試験を一人でもくもくとやっているのは個人開発の一つの姿です。

<この項は書きかけです。順次追記します。>

編纂器(Compiler)

clang --version

Debian clang version 14.0.6-++20220622053050+f28c006a5895-1~exp1~20220622173135.152
Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin

gcc --version

gcc (GCC) 12.1.0 Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

3. Terms, definitions, and symbols CN3054:2022 (1) p3.c

算譜(source code)

p3.cv
// CN3054 Committee Draft, Standard for Programming Language C
// http://www.open-std.org/jtc1/sc22/wg14/docs/papers/2022/n3054.pdf
const char * n0354 = "3. Terms, definitions, and symbols CN3054:2022 (1) p3.c";
// Debian clang version 14.0.5-++20220610033153+c12386ae247c-
// g++ (GCC) 12.1.0 Copyright (C) 2022 Free Software Foundation, Inc.
// Edited by Dr. OGAWA Kiyoshi. Compile procedure and results record.
// C++N3054:2022 Standard Working Draft on ISO/IEC 14882(0) sample code compile list

#include "n3054.h"

// 3. Terms, definitions, and symbols
//  For the purposes of this document, the terms and definitions given in ISO/IEC 2382, ISO 80000–2, and the following apply.
//  ISO and IEC maintain terminological databases for use in standardization at the following addresses: — ISO Online browsing platform: available at https://www.iso.org/obp
// - IEC Electropedia: available at http://www.electropedia.org/
//  Additional terms are defined where they appear in italic type or on the left side of a syntax rule. Terms explicitly defined in this document are not to be presumed to refer implicitly to similar terms defined elsewhere.
// 3.1 access (verb)
// - execution-time action⟩ to read or modify the value of an object
//  Note 1 to entry:
//  Note 2 to entry:
//  Note 3 to entry:
// 3.2 alignment
// Where only one of these two actions is meant, "read" or "modify" is used. "Modify" includes the case where the new value being stored is the same as the previous value. Expressions that are not evaluated do not access objects. requirement that objects of a particular type be located on storage boundaries with addresses that are particular multiples of a byte address
// 3.3 argument
// actual argument (DEPRECATED: actual parameter)
// expression in the comma-separated list bounded by the parentheses in a function call expression, or a sequence of preprocessing tokens in the comma-separated list bounded by the parentheses in a function-like macro invocation
// 3.4 behavior
// external appearance or action
// 3.4.1 implementation-defined behavior
// unspecified behavior where each implementation documents how the choice is made
//  Note 1 to entry: J.3 gives an overview over properties of C programs that lead to implementation-defined behavior.
//  EXAMPLE An example of implementation-defined behavior is the propagation of the high-order bit when a signed integer is shifted right.
// 3.4.2 locale-specific behavior
// behavior that depends on local conventions of nationality, culture, and language that each implemen- tation documents
//  Note 1 to entry: J.4 gives an overview over properties of C programs that lead to locale-specific behavior.
// EXAMPLE An example of locale-specific behavior is whether the islower function returns true for characters other than the 26 lowercase Latin letters.
// 3.4.3 undefined behavior
// behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this document imposes no requirements
//  Note 1 to entry: Possible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message).
//  Note 2 to entry: J.2 gives an overview over properties of C programs that lead to undefined behavior.
//  EXAMPLE An example of undefined behavior is the behavior on dereferencing a null pointer.
// 3.4.4 unspecified behavior
// behavior, that results from the use of an unspecified value, or other behavior upon which this document provides two or more possibilities and imposes no further requirements on which is chosen in any instance
//  Note 1 to entry: J.1 gives an overview over properties of C programs that lead to unspecified behavior.
//  EXAMPLE An example of unspecified behavior is the order in which the arguments to a function are evaluated.
// 3.5 bit
// unit of data storage in the execution environment large enough to hold an object that can have one of two values
//  Note 1 to entry: It need not be possible to express the address of each individual bit of an object.
// 3.6 byte
// addressable unit of data storage large enough to hold any member of the basic character set of the execution environment
//  Note 1 to entry: It is possible to express the address of each individual byte of an object uniquely.
//  Note 2 to entry: A byte is composed of a contiguous sequence of bits, the number of which is implementation-defined. The least significant bit is called the low-order bit; the most significant bit is called the high-order bit.
// 3.7 character
// ⟨abstract⟩ member of a set of elements used for the organization, control, or representation of data
// 3.7.1 character
// single-byte character, ⟨C⟩ bit representation that fits in a byte
// 3.7.2 multibyte character
// sequence of one or more bytes representing a member of the extended character set of either the source or the execution environment
//  Note 1 to entry: The extended character set is a superset of the basic character set.
//  3.7.3 wide character
// value representable by an object of type wchar_t, capable of representing any character in the current locale
// 3.8 constraint
// restriction, either syntactic or semantic, by which the exposition of language elements is to be interpreted
// 3.9 correctly rounded result
// representation in the result format that is nearest in value, subject to the current rounding mode, to what the result would be given unlimited range and precision
//  Note 1 to entry: In this document, when the words "correctly rounded" are not immediately followed by "result", this is the intended usage.
//  Note 2 to entry: IEC 60559 or implementation-defined rules apply for extreme magnitude results if the result format contains infinity.
// 3.10 diagnostic message
// message belonging to an implementation-defined subset of the implementation’s message output
// 3.11 forward reference
// reference to a later subclause of this document that contains additional information relevant to this subclause
// 3.12 implementation
// particular set of software, running in a particular translation environment under particular con- trol options, that performs translation of programs for, and supports execution of functions in, a particular execution environment
// 3.13 implementation limit
// restriction imposed upon programs by the implementation
// 3.14  memory location
// either an object of scalar type, or a maximal sequence of adjacent bit-fields all having nonzero width
//  Note 1 to entry: Two threads of execution can update and access separate memory locations without interfering with each other.
//  Note 2 to entry: A bit-field and an adjacent non-bit-field member are in separate memory locations. The same applies to two bit-fields, if one is declared inside a nested structure declaration and the other is not, or if the two are separated by a zero-length bit-field declaration, or if they are separated by a non-bit-field member declaration. It is not safe to concurrently update two non-atomic bit-fields in the same structure if all members declared between them are also (nonzero-length) bit-fields, no matter what the sizes of those intervening bit-fields happen to be.
//  EXAMPLE A structure declared as
struct {
    char a;
    int b:5, c:11,:0, d:8;
    struct {
        int ee:8;
    } e;
} st;
//     contains four separate memory locations: The member a, and bit-fields d and e.ee are each separate memory locations, and can be modified concurrently without interfering with each other. The bit-fields b and c together constitute the fourth memory location. The bit-fields b and c cannot be concurrently modified, but b and a, for example, can be.
// 3.15 object
// region of data storage in the execution environment, the contents of which can represent values
//  Note 1 to entry: When referenced, an object can be interpreted as having a particular type; see 6.3.2.1.
// 3.16 parameter, formal parameter, DEPRECATED: formal argument
// object declared as part of a function declaration or definition that acquires a value on entry to the function, or an identifier from the comma-separated list bounded by the parentheses immediately following the macro name in a function-like macro definition
// 3.17 recommended practice
// specification that is strongly recommended as being in keeping with the intent of the standard, but that might be impractical for some implementations
// 3.18 runtime-constraint
// requirement on a program when calling a library function
//  Note 1 to entry: Despite the similar terms, a runtime-constraint is not a kind of constraint as defined by 3.8, and need not be diagnosed at translation time.
//  Note 2 to entry: Implementations that support the extensions in Annex K are required to verify that the runtime-constraints for a library function are not violated by the program; see K.3.1.4.
//  Note 3 to entry: Implementations that support Annex L are permitted to invoke a runtime-constraint handler when they perform a trap.
// 3.19 value
// precise meaning of the contents of an object when interpreted as having a specific type
// 3.19.1 implementation-defined value
// unspecified value where each implementation documents how the choice is made
// 3.19.2 indeterminate representation
// object representation that either represents an unspecified value or is a non-value representation
// 3.19.3 unspecified value
// valid value of the relevant type where this document imposes no requirements on which value is
// 3.19.4 non-value representation
// an object representation that does not represent a value of the object type
// 3.19.5 perform a trap
// interrupt execution of the program such that no further operations are performed2)
//  Note 1 to entry: Implementations that support Annex L are permitted to invoke a runtime-constraint handler when they perform a trap.
// 3.20 ⌈x⌉ ceiling of x
// the least integer greater than or equal to x
//  EXAMPLE ⌈2.4⌉ is 3, ⌈−2.4⌉ is −2.
// 3.21 ⌊x⌋ floor of x
// the greatest integer less than or equal to x
//  EXAMPLE ⌊2.4⌋ is 2, ⌊−2.4⌋ is −3.
// 3.22 wraparound
// the process by which a value is reduced modulo 2N , where N is the width of the resulting type
int main() {
    PR3(st.a,st.b,st.c,d);
    PR2(st.d, st.e.ee, d);
    printf("%s\n", n3540);
    return EXIT_SUCCESS;
}

編纂・実行結果(compile and go)

bash

$ clang p3.c -std=11 -o p3l -I. -Wall
 st.a = 0
 st.b = 0
 st.c = 0
 st.d = 0
 st.e.ee = 0
3. Terms, definitions, and symbols CN3054:2022 (1) p3.c

$ clang p3.c -std=17 -o p3l -I. -Wall
 st.a = 0
 st.b = 0
 st.c = 0
 st.d = 0
 st.e.ee = 0
3. Terms, definitions, and symbols CN3540:2022 (1) p3.c

$ clang p3.c -std=2x -o p3l -I. -Wall
 st.a = 0
 st.b = 0
 st.c = 0
 st.d = 0
 st.e.ee = 0
3. Terms, definitions, and symbols CN3054:2022 (1) p3.c

$ gcc p3.c -std=11 -o p3g -I. -Wall
 st.a = 0
 st.b = 0
 st.c = 0
 st.d = 0
 st.e.ee = 0
3. Terms, definitions, and symbols CN3054:2022 (1) p3.c

$ gcc p3.c -std=c17 -o p3g -I. -Wall
 st.a = 0
 st.b = 0
 st.c = 0
 st.d = 0
 st.e.ee = 0
3. Terms, definitions, and symbols CN3054:2022 (1) p3.c

$ gcc p3.c -std=c2x -o p3g -I. -Wall
 st.a = 0
 st.b = 0
 st.c = 0
 st.d = 0
 st.e.ee = 0
3. Terms, definitions, and symbols CN3054:2022 (1) p3.c

検討事項(agenda)

意味のある出力。

応用例1 MISRA C/C++

MISRA C まとめ #include

MISRA C++ 5-0-16

応用例2 CERT C/C++

SEI CERT C++ Coding Standard AA. Bibliography 確認中。

MISRA C/C++, AUTOSAR C++, CERT C/C++とC/C++工業標準をコンパイルする

自己参考資料(self reference)

関連する自己参照以外は、こちらの先頭に移転。

C言語(C++)に対する誤解、曲解、無理解、爽快。

C言語教育はCコンパイラの写経で

C2011コンパイル一覧@researchmap

https://researchmap.jp/jownvh0ye-1797580/#_1797580

[C][C++]の国際規格案の例題をコンパイルするときの課題7つ。

C Puzzle Bookの有り難み5つ、C言語規格及びCコンパイラの特性を認識

dockerにclang

docker gnu(gcc/g++) and llvm(clang/clang++)

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)

astyle 使ってみた

<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>

文書履歴(document history)

ver. 0.01 初稿  20221010
ver. 0.02 N3054 URLリンク切れ 変更, C言語教育はCコンパイラの写経で URL追記 20221029
ver. 0.03 ありがとう追記 20230622

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0