Re: [Boost-users] Boost program_options
Date: Sat, 22 Aug 2009 10:22:40 +0400
From: Vladimir Prus
in program_options::parse_command_line - why can't the the argument "argv" be of type 'const charT*' rather than 'charT*'?
i ask because our unit tests were giving a bunch of errors because they were written like this..
vector< char* > cmdLine; cmdLine.push_back( "someExec" ); cmdLine.push_back( "--optflag1" ); cmdLine.push_back( "value1" ); etc.
then... char ** argv = &cmdLine[ 0 ];
then passing this to parse_command_line. when we compile under g++ 4.x we get warnings that assigning string literals to char* is a deprecated conversion. Actually I agree with the rationale, but this leaves me with a problem calling parse_command_line. Is it going to change any of these values?
No, it's not actually changing anything.
I know the c standard calls for the argv in main's prototype to be non-const, but why can't parse_command_line be more restrictive?
Because it that case, you won't be able to pass main's argv to parse_command_line. - Volodya --------------------- ok why not? you would be passing a non-const (main::argv) to a const qualified parameter. this would just guarantee that the function couldn't modify it (which is what you're telling me is the case here). i thought this was allowed. -steve
AMDG Steve Nolen wrote:
I know the c standard calls for the argv in main's prototype to be non-const, but why can't parse_command_line be more restrictive?
Because it that case, you won't be able to pass main's argv to parse_command_line.
ok why not? you would be passing a non-const (main::argv) to a const qualified parameter. this would just guarantee that the function couldn't modify it (which is what you're telling me is the case here). i thought this was allowed.
No. The standard allows conversion from char* to const char*, but not from char** to const char**. In Christ, Steven Watanabe
Steven Watanabe wrote:
AMDG
Steve Nolen wrote:
I know the c standard calls for the argv in main's prototype to be non-const, but why can't parse_command_line be more restrictive?
Because it that case, you won't be able to pass main's argv to parse_command_line.
ok why not? you would be passing a non-const (main::argv) to a const qualified parameter. this would just guarantee that the function couldn't modify it (which is what you're telling me is the case here). i thought this was allowed.
No. The standard allows conversion from char* to const char*, but not from char** to const char**.
But it allows conversion from char** to const char* const*.
participants (3)
-
Ilya Sokolov
-
Steve Nolen
-
Steven Watanabe