Handling argc==0 in the kernel
Handling argc==0 in the kernel
Posted Jan 31, 2022 8:53 UTC (Mon) by anselm (subscriber, #2796)In reply to: Handling argc==0 in the kernel by marcH
Parent article: Handling argc==0 in the kernel
First, a brief reminder that some standard requires argv[argc] to be NULL would be IMHO very useful.
FWIW, my venerable copy of ANSI/ISO 9899-1990 says, in section 5.1.2.2.1:
argv[argc] shall be a null pointer.
Perhaps this was changed in the meantime but I would be surprised.
It's not obvious that it does because why would you need a clumsy NULL terminator when you already have a proper argc?
Presumably so you can say char **p; for (p = argv; *p; p++) {…}. One might argue that this is superfluous and that people ought to be doing something like int i; for (i = 0; i < argc; i++) {…} instead, but chances are that in the run-up to ANSI/ISO 9899-1990 there were C implementations that did guarantee argv[argc] == 0 already, and the former idiom was sufficiently widespread that it was easier to mandate this for everyone than to outlaw (or leave vague) something that worked fine for a large enough number of people.
