W
WP
I saw a discussion on a forum where two people were arguing if the
following program causes undefined behaviour (or at least undefined
output for a given program name and argument) or not (ignore the
failure to check argc, assume at least one argument is passed to the
program):
#include <stdio.h>
int
main(int argc, char ** argv)
{
printf("%s got %s\n", *argv++, *argv);
return 0;
}
I think I read that the order of evaluation of the arguments is not
specified so you could get the output:
thearg got progname
if you launched with
$ progname thearg
I'd like to hear what you gurus say (alot of people hanging on forums
do not seem to realise that this is the place to go for expert advice
btw).
- WP
following program causes undefined behaviour (or at least undefined
output for a given program name and argument) or not (ignore the
failure to check argc, assume at least one argument is passed to the
program):
#include <stdio.h>
int
main(int argc, char ** argv)
{
printf("%s got %s\n", *argv++, *argv);
return 0;
}
I think I read that the order of evaluation of the arguments is not
specified so you could get the output:
thearg got progname
if you launched with
$ progname thearg
I'd like to hear what you gurus say (alot of people hanging on forums
do not seem to realise that this is the place to go for expert advice
btw).
- WP