Loose-Info.com
Last Update 2020/11/20
TOP - 各種テスト - gcc - -std= - c99

-std=c99
言語標準をc99としてコンパイル

テスト概要

その1
可変長配列、long long int、複合リテラルの項目を含むソースファイルのコンパイル
-std=オプションに c90 を指定してコンパイル実行
WARNING 警告のみでコンパイル終了・実行ファイル生成
-std=オプションに c99 を指定してコンパイル実行
PASS コンパイル終了・実行ファイル生成

その2
匿名構造体を使用したコードをコンパイル
-std=オプションに c99 を指定してコンパイル実行
WARNING 警告のみでコンパイル終了・実行ファイル生成
-std=オプションに c11 を指定してコンパイル実行
PASS コンパイル終了・実行ファイル生成

実行環境

GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1


コード例・出力内容中の表記

・実行例中の太字表記部分は、コマンドなどの入力された文字列を示します。
・「」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。

使用ファイル

各例共通

sample.h
/* -std=c99 オプション動作確認用ヘッダファイル */ #ifndef SAMPLE_H #define SAMPLE_H int sampFunc(int n); #endif /* SAMPLE_H */

main.c
/* -std=c99 オプション動作確認用ソースファイル main.c */ #include <stdio.h> #include "sample.h" int main(void) { int n = sampFunc(3); printf("n = %d\n", n); return 0; }

その1

以下の項目を含むソースファイルのコンパイル
可変長配列
long long int
複合リテラル

sample1.c
/* -std=c99 オプション動作確認用ソースファイル sample1.c */ #include <stdio.h> #include "sample.h" int sampFunc(int n) { int a[n]; /* 可変長配列 */ long long int i; /* long long int */ int j; int *pn = (int []){4, 5, 6}; /* 複合リテラル */ for (i=0; i<n; i++) { a[i] = i * i; } for (i=0; i<n; i++) { for (j=0; j<3; j++) { printf("a[%d] = %d : b[%d] = %d\n", i, a[i], j, *(pn + j)) ; } } return n; }

-std=オプションに c90 を指定してコンパイル実行
$ gcc -v -std=c90 -Wpedantic sample1.c main.c <--- -WpedanticオプションでISO C で要求される警告を出力 Using built-in specs. /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -quiet -v sample1.c ... -std=c90 ... GNU C89 (GCC) version 8.2.0 (x86_64-pc-linux-gnu) <--- 規格に関する出力(C89) compiled by GNU C version 8.2.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version none sample1.c: In function ‘sampFunc’: sample1.c:8:2: warning: ISO C90 forbids variable length array ‘a’ [-Wvla] int a[n]; 可変長配列に関する警告 ^~~ sample1.c:9:7: warning: ISO C90 does not support ‘long long’ [-Wlong-long] long long int i; long long int に関する警告 ^~~~ sample1.c:12:20: warning: ISO C90 forbids compound literals [-Wpedantic] int *pn = (int []){4, 5, 6}; 複合リテラル に関する警告 ^ COLLECT_GCC_OPTIONS='-v' '-std=c90' '-Wpedantic' '-mtune=generic' '-march=x86-64' as -v --64 -o /tmp/cc7PSHnI.o /tmp/ccpoGcHb.s /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -quiet -v main.c ... -std=c90 ... as -v --64 -o /tmp/ccV1kFdg.o /tmp/ccpoGcHb.s /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/collect2 ... COLLECT_GCC_OPTIONS='-v' '-std=c90' '-Wpedantic' '-mtune=generic' '-march=x86-64' $ ./a.out a[0] = 0 : b[0] = 4 a[0] = 0 : b[1] = 5 a[0] = 0 : b[2] = 6 a[1] = 1 : b[0] = 4 a[1] = 1 : b[1] = 5 a[1] = 1 : b[2] = 6 a[2] = 4 : b[0] = 4 a[2] = 4 : b[1] = 5 a[2] = 4 : b[2] = 6 n = 3 $ 警告のみでコンパイル終了・実行ファイル生成

-std=オプションに c99 を指定してコンパイル実行
$ gcc -v -std=c99 -Wpedantic sample1.c main.c Using built-in specs. /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -quiet -v sample1.c ... -std=c99 ... GNU C99 (GCC) version 8.2.0 (x86_64-pc-linux-gnu) <--- 規格に関する出力(C99) compiled by GNU C version 8.2.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version none as -v --64 -o /tmp/ccaI3qZn.o /tmp/ccnOUsTm.s /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -quiet -v main.c ... -std=c99 ... as -v --64 -o /tmp/ccZDqsfq.o /tmp/ccnOUsTm.s /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/collect2 ... COLLECT_GCC_OPTIONS='-v' '-std=c99' '-Wpedantic' '-mtune=generic' '-march=x86-64' $ ./a.out a[0] = 0 : b[0] = 4 a[0] = 0 : b[1] = 5 a[0] = 0 : b[2] = 6 a[1] = 1 : b[0] = 4 a[1] = 1 : b[1] = 5 a[1] = 1 : b[2] = 6 a[2] = 4 : b[0] = 4 a[2] = 4 : b[1] = 5 a[2] = 4 : b[2] = 6 n = 3 $ コンパイル終了・実行ファイル生成

その2

匿名構造体を使用したコードをコンパイル

sample2.c
/* -std=c99 オプション動作確認用ソースファイル sample2.c */ #include <stdio.h> #include "sample.h" int sampFunc(int n) { struct { struct {int i1, i2;}; /* 匿名構造体 */ } sx; sx.i1 = n * 2; sx.i2 = n * 3; printf("sx.i1 = %d : sx.i2 = %d\n", sx.i1, sx.i2); return n; }

-std=オプションに c99 を指定してコンパイル実行
$ gcc -v -std=c99 -Wpedantic sample2.c main.c Using built-in specs. /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -quiet -v sample2.c ... -std=c99 ... GNU C99 (GCC) version 8.2.0 (x86_64-pc-linux-gnu) compiled by GNU C version 8.2.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version none sample2.c: In function ‘sampFunc’: sample2.c:10:23: warning: ISO C99 doesn’t support unnamed structs/unions [-Wpedantic] struct {int i1, i2;}; 匿名構造体に関する警告 ^ sample2.c:8:2: warning: struct has no named members [-Wpedantic] struct ^~~~~~ COLLECT_GCC_OPTIONS='-v' '-std=c99' '-Wpedantic' '-mtune=generic' '-march=x86-64' as -v --64 -o /tmp/cckR3zTC.o /tmp/ccO7Rspw.s /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -quiet -v main.c ... -std=c99 ... as -v --64 -o /tmp/ccqM47tJ.o /tmp/ccO7Rspw.s /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/collect2 ... COLLECT_GCC_OPTIONS='-v' '-std=c99' '-Wpedantic' '-mtune=generic' '-march=x86-64' $ ./a.out sx.i1 = 6 : sx.i2 = 9 n = 3 $ 警告のみでコンパイル終了・実行ファイル生成

-std=オプションに c11 を指定してコンパイル実行
$ gcc -v -std=c11 -Wpedantic sample2.c main.c Using built-in specs. /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -quiet -v sample2.c ... -std=c11 ... GNU C11 (GCC) version 8.2.0 (x86_64-pc-linux-gnu) <--- 規格に関する出力(C11) compiled by GNU C version 8.2.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version none as -v --64 -o /tmp/ccRXFght.o /tmp/ccd6D88B.s /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -quiet -v main.c ... -std=c11 ... as -v --64 -o /tmp/ccd6M7xl.o /tmp/ccd6D88B.s /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/collect2 ... COLLECT_GCC_OPTIONS='-v' '-std=c11' '-Wpedantic' '-mtune=generic' '-march=x86-64' $ ./a.out sx.i1 = 6 : sx.i2 = 9 n = 3 $ コンパイル終了・実行ファイル生成