[코딩] callback example - no typedef
앞 글 처럼 typedef 를 쓰면 훨씬 이해가 쉬운 코드가 되겠지만..익숙해 지자 ^^
callback_notypedef.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
'IT > Software' 카테고리의 다른 글
tcp 소켓 프로그램 - 비정상 연결 종료시 (0) | 2018.10.19 |
---|---|
[링크] C 코딩은 여기로 (0) | 2018.08.28 |
[코딩] 함수포인터를 typedef으로 선언해서 쓰는 이유 (0) | 2018.08.28 |
[코딩] #define에 관한 이야기(#, ##, \) (0) | 2018.08.28 |
Announcing the Arduino Command Line Interface (CLI) (0) | 2018.08.28 |