Werner Messages: 234 Registered: May 2006 Location: Cologne / Germany
Experienced Member
unodgs wrote on Sat, 08 July 2006 22:32
Werner wrote on Sat, 08 July 2006 16:08
If the above code doesn't help (it doesn't comply with the C++ standard )
May I know what's wrong with it??
Sure! You have every right to know!
Here we go:
1.
dr_jumba wrote that he needs to pass the command line arguments to a 3rd party library. It seems much more likely that the "3rd party" expects these arguments to be passed in the standard C++ way than in the Ultimate++ way.
2.
So lets compare the results of your code with what the C++ standard expects:
a)
The first argument (argv[0]) expected by the C++ standard is the (path and) name of the running application. If this is not available the standard expects "argv[0][0] == '\0'".
Your code passes the 1st "real" argument as argv[0]. It suggests itself that this might mislead the receiving library.
b)
The standard expects "argv[argc] == (char* 0)".
I'm not sure whether your code guarantees that and this missing final pointer could terribly crash the library and everything else.
c)
argv itself and the strings to which it points must be modifiable.
You use "const char **argv".
d)
Finally the "application name issue" makes your cnt (= argc) carry a wrong value - 1 too few.