C
Charles Sullivan
I'm working on a program which has a "tree" of command line arguments,
i.e.,
myprogram level1 [ level2 [ level3 ...]]]
such that there can be more than one level2 argument for each level1
argument and more than one level3 argument for each level2 argument, etc.
Suppose I code it similar to this fragment:
int main( int argc, char *argv[] )
{
...
if ( strcmp(argv[1], "blivet") == 0 )
return do_blivet( --argc, ++argv );
else if ( ...
...
}
int do_blivet( int argc, char *argv[] ) {
...
if ( strcmp(argv[1], "whosis") == 0 )
return do_whosis( --argc, ++argv );
else if ( ...
...
}
It turns out to be somewhat more convenient in practise to increment
argv as above than to pass the argument (argv + 1).
My question: Is it correct C code to increment argv as above?
I'm wondering whether doing this might prevent memory
allocated for array *argv[] from being freed upon program exit,
under some operating systems.
Thanks for your advice.
Regards,
Charles Sullivan
i.e.,
myprogram level1 [ level2 [ level3 ...]]]
such that there can be more than one level2 argument for each level1
argument and more than one level3 argument for each level2 argument, etc.
Suppose I code it similar to this fragment:
int main( int argc, char *argv[] )
{
...
if ( strcmp(argv[1], "blivet") == 0 )
return do_blivet( --argc, ++argv );
else if ( ...
...
}
int do_blivet( int argc, char *argv[] ) {
...
if ( strcmp(argv[1], "whosis") == 0 )
return do_whosis( --argc, ++argv );
else if ( ...
...
}
It turns out to be somewhat more convenient in practise to increment
argv as above than to pass the argument (argv + 1).
My question: Is it correct C code to increment argv as above?
I'm wondering whether doing this might prevent memory
allocated for array *argv[] from being freed upon program exit,
under some operating systems.
Thanks for your advice.
Regards,
Charles Sullivan