Programming

구조체 이니셜 라이저에서 점 (.)은 무엇을 의미합니까?

procodes 2020. 8. 13. 21:43
반응형

구조체 이니셜 라이저에서 점 (.)은 무엇을 의미합니까?


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 };

... 마지막 두 개는 C99 전용입니다.


이것들은 C99의 지정된 이니셜 라이저 입니다.


designated initialisation( 지정된 이니셜 라이저 참조 ) 로 알려져 있습니다. "initializer-list", 각 ' .'은 ' '식별자로 지정된 개체에 대해 초기화 designator할 ' fuse_oprations'구조체 의 특정 멤버를 명명하는 ' hello_oper'입니다.

참고 URL : https://stackoverflow.com/questions/8047261/what-does-dot-mean-in-a-struct-initializer

반응형