static struct fuse_oprations hello_oper = {
.getattr = hello_getattr,
.readdir = hello_readdir,
.open = hello_open,
.read = hello_read,
};
私はこのC構文をよく理解していません。構文名がわからないので検索すらできません。あれは何でしょう?
static struct fuse_oprations hello_oper = {
.getattr = hello_getattr,
.readdir = hello_readdir,
.open = hello_open,
.read = hello_read,
};
私はこのC構文をよく理解していません。構文名がわからないので検索すらできません。あれは何でしょう?
これは、初期化子で構造体の特定のフィールドを名前で設定できるC99機能です。この前は、初期化子には、すべてのフィールドの値だけを順番に含める必要がありました。もちろん、これは引き続き機能します。
したがって、次の構造体の場合:
struct demo_s {
int first;
int second;
int third;
};
...あなたは使うことができます
struct demo_s demo = { 1, 2, 3 };
...また:
struct demo_s demo = { .first = 1, .second = 2, .third = 3 };
...あるいは:
struct demo_s demo = { .first = 1, .third = 3, .second = 2 };
...最後の2つはC99専用ですが。
これらはC99の指定された初期化子です。
として知られていますdesignated initialisation
(指定イニシャライザーを参照)。「初期化子リスト」、各' .
'は「designator
」であり、この場合fuse_oprations
、''識別子で指定されたオブジェクトに対して初期化する''構造体の特定のメンバーを指定しhello_oper
ます。
構文全体は、COD3BOYですでに説明されているように、指定初期化子として知られており、宣言時に特定の値またはデフォルト値に構造体を初期化する必要がある場合に一般的に使用されます。