I just found this.
// /usr/include/sys/signal.h // OS X
#define SIG_ERR ((void (*)(int))-1)
What does ((void (*)(int))-1)
part mean?
Is it different to
#define SIG_ERR -1
?
One should stop using the ‘void main’ if doing so. int main – ‘int main’ means that our function needs to return some integer at the end of the execution and we do so by returning 0 at the end of the program. 0 is the standard for the “successful execution of the program”. main – In C89, the unspecified return type defaults to int .
So the operating system calls this function. When some value is returned from main (), it is returned to operating system. The void main () indicates that the main () function will not return any value, but the int main () indicates that the main () can return integer type data.
When our program is simple, and it is not going to terminate before reaching the last line of the code, or the code is error free, then we can use the void main (). But if we want to terminate the program using exit () method, then we have to return some integer values (zero or non-zero). In that situation, the void main () will not work.
However, using foo (void) restricts the function to take any argument and will throw an error. Let’s see. The above code will give us an error because we have used ‘foo (void)’ and this means we can’t pass any argument to the function ‘foo’ as we were doing in the case of ‘foo ()’.
This is cast to a function-pointer:
((type) value)
Where type is void (*)(int)
which is pointer to function accepting one int
argument and returning void
, which is actually is a signature of a signal handler:
typedef void (*sighandler_t)(int);
You may decode such types with cdecl
tool or web-site: http://cdecl.org/
This is a cast of -1 into the function pointer which is expected as the type of SIG_ERR. Using -1 directly does not work at situations where the compiler needs the correct type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With