よくある質問(FAQ)

CasePlayer2で解析可能な「GNU-C」の記述を教えてください。

言語仕様(C99 or GNU-C)について

質問

CasePlayer2の「言語設定」で「GNU-C」を選択したとき、解析可能なソース記述を教えてください。

回答

CasePlayer2で解析可能なソース記述は下記の通りです。「ANSI-C」から追加された記述を掲載しています。

※制限事項について
CasePlayer2には、「GNU-C」言語仕様の解析において制限事項があります。詳細については「Windowsメニュー」⇒「GAIO CasePlayer2」⇒「ヘルプ」を辿り、CasePlayer2マニュアルをご覧ください。

■制限事項掲載位置
ー操作方法
 ー仕様書生成
  ーC仕様書生成
   ーC仕様書生成仕様
    ー拡張言語モードの制限  (※「GCC文法制限」及び「GCCの属性に関する制限」の項目に掲載されています)

■CasePlayer2で解析可能な「GNU-C」の記述

① ダブルワード整数
long long int a = 123LL;
unsigned long long int b = 123ULL;

② 複素数
_Complex double a;
③ 可変長配列
void func (char *s1, char *s2)
{
 char str[strlen (s1) + strlen (s2)+ 1];
 strcpy (str, s1);
 strcat (str, s2);
}

void func (int len, char data[len][len])
{
 /*...*/
}

④ 長さゼロの配列
struct line {
 int length;
 char contents[0];
};

⑤ メンバーを持たない構造体
struct empty
{
 /* 空 */
};

⑥ 名前のない構造体と共用体フィールド
struct {
 int a;
 union {
  int b;
  float c;
 }; /*▲ 名前なし */
 int d;
} uni;

struct {
 int a;
 struct {
  int b;
 }; /*▲ 名前なし */
} str;

int us;
void func ()
{
 us = uni.b;
 us = str.b;
}

⑦ 左辺値でない配列は添字を持つことができる
struct tags  
{
 int a[4];
};
struct tags _sub();

int func (int index)
{
 return _sub().a[index];
}

⑧ 動的初期化子
void func (int f, int g)
{
 int array[2] = { f-g, f+g };
}

⑨ 複合リテラル
struct lit {
 int a;
 char b[2];
};

void func (int x, int y)
{
 struct lit s;
 s = (struct lit) {x + y, 'a', 0};
}

⑩ 指定初期化子
int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };

struct point {
 int x, y;
};
struct point pdata = { .y = 100, .x = 200 };

⑪ 関数の属性 宣言
__attribute__ ((access (read_only, 2, 3))) void* memcpy (void*, const void*, size_t);
void func () __attribute__ ((weak, alias ("__func")));
void func () __attribute__ ((noreturn));

⑫ 変数の属性 宣言
int data __attribute__ ((aligned (16))) = 0;

struct cattr
{
 char a;
 int lx[2] __attribute__ ((packed));
};

⑬ 型の属性 宣言
struct __attribute__ ((aligned (8))) cmtype {
 short a[3];
};
typedef int more __attribute__ ((aligned (8)));

⑭ 文の属性 宣言
void func7(int cond)
{
 switch (cond)
 {
  case 1:
   bar (1);
   __attribute__((fallthrough));
  case 2:
   ;
 }
}

⑮ スレッドローカルストレージ
__thread int th_d;
static __thread char *th_p;

⑯ インライン関数
static inline int sub (int *a)
{
 return (*a)++;
}

void func (int *arg)
{
 int d = sub (arg);
}

⑰ インラインアセンブリ記述
int asm_src = 1;
int asm_msr, asm_dst;

void func ()
{
 asm ("mov %1, %0\n\t"
  "add $1, %0"
  : "=r" (asm_dst)
  : "r" (asm_src));


 asm volatile ( "rdtsc\n\t"
  "shl $32, %%rdx\n\t"
  "or %%rdx, %0"
  : "=a" (asm_msr)
  :
  : "rdx") ;

}

⑱ 式内の文と宣言
#define maxint(a,b) ({int _a = (a), _b = (b); _a > _b ? _a : _b; })

void func (int a, int b)
{
 int s = maxint(1, 2);
 s = ({int _a = (a), _b = (b); _a > _b ? _a : _b; });
}

⑲ ローカルに宣言されたラベル
void func ()
{
 {
  __label__ exit;
  for (int i = 0; i < 10; i++) {
   if (i == 5) goto exit;
  }
 exit: ;
 }

 {
  __label__ exit;
  while (1) { goto exit; }
 exit: ;
 }
}

⑳ typeof による型の参照
int ya=123;
typeof (ya) yb;

void func ()
{
 yb = ya;
}

㉑ offsetofマクロ
#include <stddef.h> /* ヘッダ内に「offsetof」マクロが定義されています */

struct tagof {
 char name[16];
 short age;
 long data;
};

void func ()
{
 int ofst = offsetof (struct tagof, age);
}

㉒ 関数、型、変数のアラインメント
char string[13];
int align_int = __alignof__(int);
int align_char = __alignof__(char);
int align_ar = __alignof__(string);

㉓ _Bool 型
_Bool flag;
㉔ 可変引数を持つマクロ
#define dbg(format, ...) printf (format, __VA_ARGS__)

void func ()
{
 dbg("**%s,%d\n","test", 10);
}

㉕ 省略されたオペランドを持つ条件式
int ox=0, oy=1;
int oz=123;

void func ()
{
 oz = ox ? /*省略*/ :  oy;
}

㉖ case文の範囲
void func (int a)
{
 switch (a)
 {
  case 1 ... 5:
   a = 1;
   break;
  case 6:
   a = 2;
 }
}

㉗ 宣言、ラベル、およびコードの混在
void func ()
{
 int i;

 i++;
 int j = i + 2;
}

㉘ 16進浮動小数点数
double hexd = 0x1.23ap32;
㉙「0b」接頭辞を使用した二進定数
int bint = 0b101010;
㉚ 文字列としての関数名
void func ()
{
 printf ("実行中の関数 = %s\n", __FUNCTION__);
}

㉛ 定義済みマクロ名
/* C言語のバージョン(199901L) */
long version = __STDC_VERSION__;

■注意事項
「__STDC_VERSION__」のディフォルト値は、C99のバージョン(199901L)になっています。
システムインクルード(stdio.h 等)内で「__STDC_VERSION__」マクロを参照している場合は、GNU-Cバージョンへ再定義をする必要があります。
--[再定義 例]-------------------------------------
#undef __STDC_VERSION_
#define __STDC_VERSION__ 201112L
-----------------------------------------------------