On Dec 19, 2005, at 12:15 PM, Shawn Erickson wrote:
If no built-in feature exists I will simply grab the arguments while
in main and stash what I need in a global var for later use or
accessible via some internal api.
That's what I always do.
I suppose it might be possible to walk backward from environ to get
the command line parameters:
int main( int argc, char **argv )
{
print_args();
return 0;
}
$ gcc -Wall args.c
$ ./a.out This is a test.
./a.out This is a test.
That said, it's probably easier and safer to just store them. The
above code assume that argv[0] is the path of the program which
doesn't have to be the case. It also assumes that sizeof( int ) ==
sizeof( char * ), also not a reasonable assumption to make for
portable code. Lastly, it assumes that the arguments to main are laid
out in memory in the order:
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden
This email sent to email@hidden