This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Can argv be NULL in C?
- From: Yao Qi <qiyaoltc at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Cc: Luis Machado <lgustavo at codesourcery dot com>
- Date: Fri, 7 Oct 2016 17:40:35 +0100
- Subject: Can argv be NULL in C?
- Authentication-results: sourceware.org; auth=none
Hi,
Luis has a GDB patch https://sourceware.org/ml/gdb-patches/2016-10/msg00137.html
which checks whether argv is NULL or not, because argv is NULL in
his env (aarch64-elf).
Can argv be NULL in C? In C standard, argc and argv is specified
in "hosted environment", so argv can't be NULL in "hosted environment".
The program start-up is implementation-defined in "freestanding
environment". Then, in practise, is bare-metal a "freestanding
environment"? The bare-metal may still have its C library, like newlib,
so is it a "freestanding environment" or "hosted environment"?
In this particular case, the C code has main function, so it expects
argument passing (argc and argv) from somewhere else, so my
understanding is that it is "hosted environment", and its argv must
be non-NULL.
--
Yao (齐尧)