やってきました。
gcc(gnu) clang(llvm)コンパイルエラー比較
長らくごぶさたしていました。
MISRA の解説書は有料ですが、Codeは無償であげてくれています。
MISRA C:2012 Example-Suite
https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite
<この項は書きかけです。順次追記します。>
This article is not completed. I will add some words in order.
全体の記録
Misra Example Suite at docker コンパイル完了までの道のり
https://qiita.com/kaizen_nagoya/items/71f04a0204d5a1114577
順にコンパイルエラーが出たものを比較し、
エラーを取るのなら取ってみます。
-Wall でコンパイルしています。
R_11_0x.c
$ clang
R_11_01.c:49:24: error: operand of type 'float' cannot be cast to a pointer type
fp16 fp4 = ( fp16 ) 1.0e6F; /* Non-compliant - float to function pointer */
^~~~~~
1 error generated.
R_11_04.c:27:20: warning: cast to 'uint8_t *' (aka 'unsigned char *') from smaller integer type 'int32_t' (aka 'int') [-Wint-to-pointer-cast]
uint8_t *q = ( uint8_t * ) addr; /* Non-compliant */
^
1 warning generated.
R_11_06.c:28:19: error: operand of type 'float' cannot be cast to a pointer type
p = ( void * ) 1024.0f; /* Non-compliant - undefined */
^~~~~~~
1 error generated.
R_11_07.c:28:24: error: pointer cannot be cast to type 'float32_t' (aka 'float')
f = ( float32_t ) p; /* Non-compliant */
^
R_11_07.c:29:24: error: operand of type 'float32_t' (aka 'float') cannot be cast to a pointer type
p = ( int16_t * ) f; /* Non-compliant */
^
2 errors generated.
R_11_09.c:34:13: warning: unused variable 'p3' [-Wunused-variable]
int32_t *p3 = MY_NULL_3; /* Compliant */
^
1 warning generated.
$ gcc
R_11_01.c: In function 'R_11_1':
R_11_01.c:49:4: error: cannot convert to a pointer type
49 | fp16 fp4 = ( fp16 ) 1.0e6F; /* Non-compliant - float to function pointer */
| ^~~~
R_11_01.c:58:9: warning: unused variable 'fp5' [-Wunused-variable]
58 | fp16 fp5 = f1; /* Compliant - exception */
| ^~~
R_11_01.c:49:9: warning: unused variable 'fp4' [-Wunused-variable]
49 | fp16 fp4 = ( fp16 ) 1.0e6F; /* Non-compliant - float to function pointer */
| ^~~
R_11_01.c:47:9: warning: unused variable 'fp3' [-Wunused-variable]
47 | fp16 fp3 = ( fp16 ) 0x8000; /* Non-compliant - integer to function pointer */
| ^~~
R_11_04.c: In function 'R_11_4':
R_11_04.c:26:20: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
26 | int32_t addr = ( int32_t ) &p; /* Non-compliant */
| ^
R_11_04.c:27:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
27 | uint8_t *q = ( uint8_t * ) addr; /* Non-compliant */
| ^
R_11_06.c: In function 'R_11_6':
R_11_06.c:28:4: error: cannot convert to a pointer type
28 | p = ( void * ) 1024.0f; /* Non-compliant - undefined */
| ^
R_11_06.c:30:8: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
30 | u = ( uint32_t ) p; /* Non-compliant - implementation-defined */
| ^
R_11_07.c: In function 'R_11_7':
R_11_07.c:28:6: error: pointer value used where a floating-point was expected
28 | f = ( float32_t ) p; /* Non-compliant */
| ^
R_11_07.c:29:6: error: cannot convert to a pointer type
29 | p = ( int16_t * ) f; /* Non-compliant */
| ^
R_11_09.c: In function 'R_11_9':
R_11_09.c:34:13: warning: unused variable 'p3' [-Wunused-variable]
34 | int32_t *p3 = MY_NULL_3; /* Compliant */
| ^~
In file included from clear_lib.c:10:
clear_lib.c: In function 'g':
clear_lib.c:263:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
263 | PR1((int)p,d);
| ^
misra_c.h:66:54: note: in definition of macro 'PR1'
66 | #define PR1(a,b) (void)printf(" "#a " = %" #b "\n", a)
| ^
clear_lib.c: In function 'use_const_volatile_char_ptr':
clear_lib.c:276:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
276 | PR1((int)cv_cp,d);
| ^
misra_c.h:66:54: note: in definition of macro 'PR1'
66 | #define PR1(a,b) (void)printf(" "#a " = %" #b "\n", a)
| ^
docker hubでの作業
docker hubからの起動はこちら。
$ docker run it kaizenjapan/misra_c_2012_example /bin/bash
#参考資料
仮説・検証(173)C言語(C++)に対する誤解、曲解、無理解、爽快。
[C][C++]の国際規格案の例題をコンパイルするときの課題7つ。
https://qiita.com/kaizen_nagoya/items/5f4b155030259497c4de
C Puzzle Bookの有り難み5つ、C言語規格及びCコンパイラの特性を認識
https://qiita.com/kaizen_nagoya/items/d89a48c1536a02ecdec9
MISRA C まとめ #include
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9
どうやって MISRA Example Suiteをコンパイルするか
https://qiita.com/kaizen_nagoya/items/fbdbff5ff696e2ca7f00
ISO/IEC TS 17961:2013 C Secure Coding Rules(1) All list(to be confirmed)
https://qiita.com/kaizen_nagoya/items/54e056195c4f11b850a1
Autosar Guidelines C++14 example code compile list
https://qiita.com/kaizen_nagoya/items/8ccbf6675c3494d57a76
C++ N4741, N4606, N3242 Source Compile Error List
https://qiita.com/kaizen_nagoya/items/2e736e04339b340ffb4d
自己参照
Error一覧 error(0)
https://qiita.com/kaizen_nagoya/items/48b6cbc8d68eae2c42b8
プログラマが知っていると良い「公序良俗」
https://qiita.com/kaizen_nagoya/items/9fe7c0dfac2fbd77a945
Ethernet 記事一覧 Ethernet(0)
https://qiita.com/kaizen_nagoya/items/88d35e99f74aefc98794
Wireshark 一覧 wireshark(0)、Ethernet(48)
https://qiita.com/kaizen_nagoya/items/fbed841f61875c4731d0
線網(Wi-Fi)空中線(antenna)(0) 記事一覧(118/300目標)
https://qiita.com/kaizen_nagoya/items/5e5464ac2b24bd4cd001
通信記事100
https://qiita.com/kaizen_nagoya/items/1d67de5e1cd207b05ef7
一覧の一覧( The directory of directories of mine.) Qiita(100)
https://qiita.com/kaizen_nagoya/items/7eb0e006543886138f39
<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>
This article is an individual impression based on the individual's experience. It has nothing to do with the organization or business to which I currently belong.
文書履歴(document history)
ver. 0.01 add URL 20240514
最後までおよみいただきありがとう4ざいました。
いいね 💚、フォローをお願いします。
Thank you very much for reading to the last sentence.
Please press the like icon 💚 and follow me for your happy life.