✅ 목표 (Goal)

typedef 를 사용하면 콜백함수를 훨씬 더 깔끔하게 사용할수 있다.

🥕 당근이의 한마디

콜백함수에서 typedef는 가급적 나중에 쓰는것이 좋겠다.

아래와 같이 구조체 사용시 왼쪽과 오른쪽은 동일한데

왼쪽 문법을 낯설어 하는 친구들이 종종 있다.

struct _sutdent_t {
	char name[];
	char age;
};

struct student_t student;
typedef struct _sutdent_t {
	char name[];
	char age;
} sutdent_t ;

student_t student;

함수 포인터도 뭐 마찬가지이다.

void bts() {
	// blah blah
}

void (*fp)();
fp= bts;

void bts() {
	// blah blah
}

typedef (*fp_t)();
fp_t fp;
fp= bts;

그런데 오른쪽의 사용법만 알고, 왼쪽의 사용법을 모른다는게 말이 안되므로

가급적 불편하지만 처음에는 불편하지만 연습을 좀하다가

충분히 숙달이 되면 typedef를 사용하면 좋겠다.

void recv_func(void (*fp)(int, int), int a, int b) { // (1)
    fp(a, b);
}

typedef void (*fp_bts)(int, int);

void recv_func(fp_bts fp, int a, int b) { // (2)
    fp(a, b);
}