argv and handling errorsAuthors: Jay Ghiron
Date: 2026-08-25
Submitted against: C23
Status: Open
Cross-references: 0065
In DR 65 wording was needed to ensure that using locales did not make programs not strictly conforming. However, there are many other things that are unspecified or implementation-defined which ought to be allowed in strictly conforming programs. For example:
If the value of
argcis greater than zero, the array membersargv[0]throughargv[argc-1]inclusive shall contain pointers to strings, which are given implementation-defined values by the host environment prior to program startup.
(C23 5.2.2.3.2 "Program startup" paragraph 2.)
The values of the strings in argv are implementation-defined, so it
appears that strictly conforming programs cannot use them in a way
that affects the observable behavior. Moreover, argc is not defined
nor stated to be implementation-defined so it appears to be
unspecified and therefore cannot be used in a way that affects the
observable behavior by strictly conforming programs:
int main(int argc,char**){
return argc;
}
The result of this program depends upon what argc is, which is
unspecified so it appears this program is not strictly conforming.
For functions that can fail such as malloc it is also unspecified
whether or not they succeed:
#include<stdio.h>
#include<stdlib.h>
int main(){
char*p=malloc(2);
if(p){
*p='h';
p[1]=0;
puts(p);
free(p);
}else{
puts("malloc failed");
}
}
The output depends upon whether malloc(2) succeeds, which is
unspecified so it appears this program is also not strictly
conforming. puts can also fail, so even just the following program
appears to not be strictly conforming:
#include<stdio.h>
int main(){
puts("h");
}
If puts("h") fails, the output would be different than if it
succeeded. Surely it is not intended for these three programs to not
be strictly conforming.