0
0

gcc(gnu), clang(llvm)コンパイルエラー・警告比較(5) R_08_04.c。docker(159) error(49)

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_08

$ clang 
R_08_01.c:22:8: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
extern x;                                      /* Non-compliant - implicit int type */
~~~~~~ ^
R_08_01.c:25:8: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
extern f ( void );                             /* Non-compliant - implicit int return type */
~~~~~~ ^
R_08_01.c:28:31: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
extern void g ( char c, const k );              /* Non-compliant - implicit int for parameter k */
                        ~~~~~ ^
R_08_01.c:32:12: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
typedef ( *pfi )( void );                       /* Non-compliant - implicit int return type */
~~~~~~~    ^
R_08_01.c:35:31: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
typedef void ( *pfv ) ( const x );              /* Non-compliant  - implicit int for parameter x */
                        ~~~~~ ^
R_08_01.c:41:10: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
   const y;                 /* Non-compliant - implicit int type */
   ~~~~~ ^
R_08_01.c:47:17: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
        const   y1;   /* Non-compliant - implicit int for member y */
        ~~~~~   ^
R_08_01.c:41:10: warning: unused variable 'y' [-Wunused-variable]
   const y;                 /* Non-compliant - implicit int type */
         ^
R_08_01.c:42:18: warning: unused variable 'y_ok' [-Wunused-variable]
   const int16_t y_ok;      /* Compliant     - explicit type */
                 ^
9 warnings generated.
R_08_03.c:30:13: error: conflicting types for 'g3'
       void g3 (        int * p1 );   /* Non-compliant - type qualifiers do not match
            ^
R_08_03.c:29:13: note: previous declaration is here
extern void g3 ( const  int * p1 );
            ^
R_08_03.c:59:6: error: conflicting types for 'g3'
void g3 ( int * p1 )  /* also breaks R.8.13 */
     ^
R_08_03.c:29:13: note: previous declaration is here
extern void g3 ( const  int * p1 );
            ^
2 errors generated.
R_08_04.c:27:17: warning: 'extern' variable has an initializer [-Wextern-initializer]
extern uint16_t speed = 6000u; /* Non-compliant - no declaration prior to this definition */
                ^
R_08_04.c:55:6: error: conflicting types for 'func43'
void func43 ( int16_t x, uint16_t y )
     ^
./R_08_04.h:28:13: note: previous declaration is here
extern void func43 ( int16_t x, int16_t y );
            ^
1 warning and 1 error generated.
R_08_08.c:25:16: warning: 'extern' variable has an initializer [-Wextern-initializer]
extern int32_t y8 = 10;     /* definition: external linkage: Breaks rule 8.4 */
               ^
R_08_08.c:26:16: error: static declaration of 'y8' follows non-static declaration
static int32_t y8;          /* internal linkage: Breaks rule 8.8 */
               ^
R_08_08.c:25:16: note: previous definition is here
extern int32_t y8 = 10;     /* definition: external linkage: Breaks rule 8.4 */
               ^
R_08_08.c:44:16: error: static declaration of 'h8' follows non-static declaration
static int32_t h8 ( void )   /* definition : internal linkage. Breaks rule 1.3 */
               ^
R_08_08.c:43:9: note: previous declaration is here
int32_t h8 ( void );         /* declaration: external linkage */
        ^
1 warning and 2 errors generated.
R_08_13_2.c:21:7: error: read-only variable is not assignable
   *p = 0;  /* Constraint Error */
   ~~ ^
1 error generated.

$ gcc 
R_08_01.c:22:8: warning: type defaults to 'int' in declaration of 'x' [-Wimplicit-int]
   22 | extern x;                                      /* Non-compliant - implicit int type */
      |        ^
R_08_01.c:25:8: warning: type defaults to 'int' in declaration of 'f' [-Wimplicit-int]
   25 | extern f ( void );                             /* Non-compliant - implicit int return type */
      |        ^
R_08_01.c:28:31: warning: type defaults to 'int' in declaration of 'k' [-Wimplicit-int]
   28 | extern void g ( char c, const k );              /* Non-compliant - implicit int for parameter k */
      |                               ^
R_08_01.c:32:12: warning: type defaults to 'int' in declaration of 'pfi' [-Wimplicit-int]
   32 | typedef ( *pfi )( void );                       /* Non-compliant - implicit int return type */
      |            ^~~
R_08_01.c:35:31: warning: type defaults to 'int' in declaration of 'x' [-Wimplicit-int]
   35 | typedef void ( *pfv ) ( const x );              /* Non-compliant  - implicit int for parameter x */
      |                               ^
R_08_01.c: In function 'R_8_1':
R_08_01.c:41:10: warning: type defaults to 'int' in declaration of 'y' [-Wimplicit-int]
   41 |    const y;                 /* Non-compliant - implicit int type */
      |          ^
R_08_01.c:47:17: warning: type defaults to 'int' in declaration of 'y1' [-Wimplicit-int]
   47 |         const   y1;   /* Non-compliant - implicit int for member y */
      |                 ^~
R_08_01.c:42:18: warning: unused variable 'y_ok' [-Wunused-variable]
   42 |    const int16_t y_ok;      /* Compliant     - explicit type */
      |                  ^~~~
R_08_01.c:41:10: warning: unused variable 'y' [-Wunused-variable]
   41 |    const y;                 /* Non-compliant - implicit int type */
      |          ^
R_08_03.c:30:13: error: conflicting types for 'g3'
   30 |        void g3 (        int * p1 );   /* Non-compliant - type qualifiers do not match
      |             ^~
R_08_03.c:29:13: note: previous declaration of 'g3' was here
   29 | extern void g3 ( const  int * p1 );
      |             ^~
R_08_03.c:59:6: error: conflicting types for 'g3'
   59 | void g3 ( int * p1 )  /* also breaks R.8.13 */
      |      ^~
R_08_03.c:29:13: note: previous declaration of 'g3' was here
   29 | extern void g3 ( const  int * p1 );
      |             ^~
R_08_04.c:27:17: warning: 'speed' initialized and declared 'extern'
   27 | extern uint16_t speed = 6000u; /* Non-compliant - no declaration prior to this definition */
      |                 ^~~~~
R_08_04.c:55:6: error: conflicting types for 'func43'
   55 | void func43 ( int16_t x, uint16_t y )
      |      ^~~~~~
In file included from R_08_04.c:22:
R_08_04.h:28:13: note: previous declaration of 'func43' was here
   28 | extern void func43 ( int16_t x, int16_t y );
      |             ^~~~~~
R_08_08.c:25:16: warning: 'y8' initialized and declared 'extern'
   25 | extern int32_t y8 = 10;     /* definition: external linkage: Breaks rule 8.4 */
      |                ^~
R_08_08.c:26:16: error: static declaration of 'y8' follows non-static declaration
   26 | static int32_t y8;          /* internal linkage: Breaks rule 8.8 */
      |                ^~
R_08_08.c:25:16: note: previous definition of 'y8' was here
   25 | extern int32_t y8 = 10;     /* definition: external linkage: Breaks rule 8.4 */
      |                ^~
R_08_08.c:44:16: error: static declaration of 'h8' follows non-static declaration
   44 | static int32_t h8 ( void )   /* definition : internal linkage. Breaks rule 1.3 */
      |                ^~
R_08_08.c:43:9: note: previous declaration of 'h8' was here
   43 | int32_t h8 ( void );         /* declaration: external linkage */
      |         ^~
R_08_13_2.c: In function 'h13':
R_08_13_2.c:21:7: error: assignment of read-only location '*p'
   21 |    *p = 0;  /* Constraint Error */
      |       ^
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++)に対する誤解、曲解、無理解、爽快。
https://qiita.com/kaizen_nagoya/items/3f3992c9722c1cee2e3a

[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 20240510

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

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

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