What is the use of the value parameter in glutTimerFunc?

Started by
1 comment, last by tonysameh 14 years, 6 months ago
The first argument is the "to be slept" time and the second is the pointer to the callback function. But why do I have to provide another integer to this callback function, which is the third argument in glutTimerFunc?
Advertisement
So that you can associate context with callback. The int will be passed to callback function.

Third parameter can be anything - only you know what it means. Example:
void callback(int value) {  switch (int) {    case 1 : printf("Hello");    case 2 : printf("World");  }};...glutTimerFunc(100, callback, 1);glutTimerFunc(200, callback, 2);
Here, same function is used, different parameter will be passed.

This is common idiom for asynchronous invocation, where the caller will be long gone when the callback is invoked.
Quote:Original post by Antheus
So that you can associate context with callback. The int will be passed to callback function.

Third parameter can be anything - only you know what it means. Example:
void callback(int value) {  switch (int) {    case 1 : printf("Hello");    case 2 : printf("World");  }};...glutTimerFunc(100, callback, 1);glutTimerFunc(200, callback, 2);
Here, same function is used, different parameter will be passed.

This is common idiom for asynchronous invocation, where the caller will be long gone when the callback is invoked.




OK thanks a lot.
I was a little confused as I thought this parameter is part of the timing.
You made it clear that it is only used to pass any information to the callback.

This topic is closed to new replies.

Advertisement