0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

gcc(gnu), clang(llvm)コンパイルエラー・警告比較(6) R_09_0x.c, docker(160) error(55)

Last updated at Posted at 2020-09-03

やってきました。

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_09_0x.c

$ clang 
R_09_01.c:48:10: warning: variable 'x' is uninitialized when used here [-Wuninitialized]
     x = x + 1u;      /* Non-compliant - x has not been been assigned a value */
         ^
R_09_01.c:46:6: note: variable 'x' is declared here
     uint16_t x = 10u;
     ^
1 warning generated.
R_09_02.c:22:29: warning: suggest braces around initialization of subobject [-Wmissing-braces]
   int16_t y1[ 3 ][ 2 ] = { 1, 2, 0, 0, 5, 6 };             /* Non-compliant */
                            ^~~~
                            {   }
R_09_02.c:22:35: warning: suggest braces around initialization of subobject [-Wmissing-braces]
   int16_t y1[ 3 ][ 2 ] = { 1, 2, 0, 0, 5, 6 };             /* Non-compliant */
                                  ^~~~
                                  {   }
R_09_02.c:22:41: warning: suggest braces around initialization of subobject [-Wmissing-braces]
   int16_t y1[ 3 ][ 2 ] = { 1, 2, 0, 0, 5, 6 };             /* Non-compliant */
                                        ^~~~
                                        {   }
R_09_02.c:33:31: warning: suggest braces around initialization of subobject [-Wmissing-braces]
   float32_t a1[ 3 ][ 2 ] = { 0 };                         /* Compliant      */
                              ^
                              {}
4 warnings generated.
R_09_03.c:39:34: warning: suggest braces around initialization of subobject [-Wmissing-braces]
   uint16_t au_3_2[ 3 ][ 2 ] = { 0U };     /* Non-compliant */
                                 ^~
                                 { }
R_09_03.c:43:36: warning: suggest braces around initialization of subobject [-Wmissing-braces]
   float32_t af_3_2[ 3 ][ 2 ]  = { 0.0F }; /* Non-compliant */
                                   ^~~~
                                   {   }
R_09_03.c:45:33: warning: suggest braces around initialization of subobject [-Wmissing-braces]
   float32_t arr2[ 3 ][ 2 ] = { 0 };  /* Compliant by exception 1 */
                                ^
                                {}
3 warnings generated.
R_09_04.c:25:52: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
    uint16_t a[ 2 ] = { [ 0 ] = *glob_p++, [ 0 ] = 1u };    /* Non-compliant, also breaks R.13.3, R.13.4 */
                                                   ^~
R_09_04.c:25:33: note: previous initialization is here
    uint16_t a[ 2 ] = { [ 0 ] = *glob_p++, [ 0 ] = 1u };    /* Non-compliant, also breaks R.13.3, R.13.4 */
                                ^~~~~~~~~
R_09_04.c:41:28: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
                     [2] = -2, [4] = -1 };                      /* Non-compliant: a3 is -5, -4, -2, 0, -1      */
                           ^~
R_09_04.c:40:48: note: previous initialization is here
   int32_t a3[5] = { [0] = -5, [1] = -4, [2] = -3,
                                               ^~
R_09_04.c:58:51: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
   struct mystruct s3 = { .a = 100, .b = -1, .a = 42, .d = 999 };         /* Non-compliant: s4 is 42, -1, 0, 999         */
                                                  ^~
R_09_04.c:58:32: note: previous initialization is here
   struct mystruct s3 = { .a = 100, .b = -1, .a = 42, .d = 999 };         /* Non-compliant: s4 is 42, -1, 0, 999         */
                               ^~~
3 warnings generated.

$ gcc 
R_09_01.c: In function 'jmp_over_init':
R_09_01.c:48:8: warning: 'x' is used uninitialized in this function [-Wuninitialized]
   48 |      x = x + 1u;      /* Non-compliant - x has not been been assigned a value */
      |      ~~^~~~~~~~
R_09_02.c: In function 'R_9_2':
R_09_02.c:22:27: warning: missing braces around initializer [-Wmissing-braces]
   22 |    int16_t y1[ 3 ][ 2 ] = { 1, 2, 0, 0, 5, 6 };             /* Non-compliant */
      |                           ^
      |                             {   } {   } {    }
R_09_03.c: In function 'R_9_3':
R_09_03.c:43:34: warning: missing braces around initializer [-Wmissing-braces]
   43 |    float32_t af_3_2[ 3 ][ 2 ]  = { 0.0F }; /* Non-compliant */
      |                                  ^
      |                                    {    }
R_09_04.c: In function 'f4':
R_09_04.c:25:52: warning: initialized field with side-effects overwritten [-Woverride-init-side-effects]
   25 |     uint16_t a[ 2 ] = { [ 0 ] = *glob_p++, [ 0 ] = 1u };    /* Non-compliant, also breaks R.13.3, R.13.4 */
      |                                                    ^~
R_09_04.c:25:52: note: (near initialization for 'a[0]')
In file included from clear_lib.c:10:
clear_lib.c: In function 'g':
clear_lib.c:261:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  261 |  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:274:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  274 |  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.

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?