본문 바로가기

[코딩] callback example - no typedef

앞 글 처럼 typedef 를 쓰면 훨씬 이해가 쉬운 코드가 되겠지만..익숙해 지자 ^^

callback_notypedef.c


#include<stdio.h>
// the callback function, which should match the
// the signature of the callback function, i.e
// pNotifyChange here
int onNotify(int nProgress){
printf("Current progress: %d\n", nProgress);
return 1;
}
// Be careful with the signature of the parameter here
// which is a function pointer
int download(int (*notify)(int))
{
int i = 0;
int step = 20;
for (; i <= 100; i += step){
notify(i); // callback is called
}
}
int main(){
int (*notify)(int) = onNotify;
download(notify);
return 0;
}



네이버밴드네이버블로그핀터레스트텔레그램링크드인포켓레딧이메일

B로그0간

개발 관련 글과 유용한 정보를 공유하는 공간입니다.