C언어에서 함수포인터를 typedef 로 선언하면 어떤 효과가 있나요 ?

dingkyu의 이미지

소스코드 분석중 다음과 같은 코드를 발견하였습니다.

typedef void (*FUNCTION)(int number, char *pName);

이렇게 정의해 놓고 다른 함수의 인수에서 위의 FUNCTION을 받는 부분을 보았습니다. 다음과 같습니다.

BOOL someFunction(HINSTANCE hInstance, FUNCTION callback)
{
....
}

궁금한 것은 위처럼 함수포인터를 typedef 로 선언하게 되면 어떤 효과가 있는지 이해를 못하겠습니다. 밑에 함수에 인수로서 다른 함수포인터를 받기위해 그냥 저렇게 하나의 데이터타잎으로 만든것인지,...

이렇게 하는 테크닉에 대해 설명해 주시면 고맙겠습니다.

doraq의 이미지

BOOL someFunction(HINSTANCE hInstance, void (*callback)(int number, char *pName))
{
}

이렇게 쓰는거랑 똑같지만 보기좋고, 짧다는거.

cppig1995의 이미지

va_arg 등 복잡한 매크로와 연관된 경우라면 typedef를 써야만 할 수도 있습니다.
http://cinsk.org/cfaqs/html/node17.html#15.11

물론 대부분의 경우에는 미관상의 이유나 Win32 API에서 HANDLE, HWND, HFILE 등을 모두 별도로 typedef하는 것과 같은 이유에서 사용합니다.

> What is the difference between software and hard water?
} Bugs drown in hard water, but live forever in software.

Real programmers /* don't */ comment their code.
If it was hard to write, it should be /* hard to */ read.

ifree의 이미지

typedef void (*FUNCTION)(int number, char *pName);

vector '<'FUNCTION'>' _functions;

cppig1995의 이미지

std::vector<void (*)(int, char *)> _functions;
이 코드도 잘 동작합니다.

> What is the difference between software and hard water?
} Bugs drown in hard water, but live forever in software.

Real programmers /* don't */ comment their code.
If it was hard to write, it should be /* hard to */ read.