Hello all I hope you can help me understand why getopt used an int and the handling of the optopt variable in getopt. Pretty new to C++.
Looking at getopt, optopt is defined as an integer. http://www.gnu.org/software/libtool/manual/libc/Using-Getopt.html#Using-Getopt
and the example here, http://www.gnu.org/software/libtool/manual/libc/Example-of-Getopt.html#Example-of-Getopt
In this example the part I do not understand is how `c', an integer is being compared to a char in the switch statement.
As I understand it the main argument geopt is working though is the character array argv so that fact that it deals returns an int seems strange to me, my expectation would be an char and that I would be required to cast any numerical arguments to int. Is the char being automatically converted to it's ANSI code and back again or something? The printf statment
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
Is expecting a char as I understand it, but being given an int. Why would getopt use int when it's dealing with a character array?
Am I missing something really obvious? I must be.