This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: No error message when format string is passed as variable to printf functions family
- From: Martin Sebor <msebor at redhat dot com>
- To: john smith <wempwer at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 13 May 2015 16:59:28 -0600
- Subject: Re: No error message when format string is passed as variable to printf functions family
- Authentication-results: sourceware.org; auth=none
- References: <CAKmQUfZNp3JSOcEt8vOFon-CyFc3_RNwW4XB5B8TR3XWSLfz4g at mail dot gmail dot com> <5553C3F0 dot 5000407 at redhat dot com> <CAKmQUfYb0R=gHA2OtXnS541Ss=Z0mgEVt4WyeC3eGiSNBh=3aQ at mail dot gmail dot com>
But why is indirection done when string is defined as an array and not
when it is a pointer to constant string?
There is no indirection in the array case. A char array
declaration with an initializer defines exactly one object:
the array whose value is the string.
const char one_object[] = "abc";
A char pointer definition with an initializer, on the other
hand, defines two objects: the pointer and the string it
points to.
const char* const two_objects = "abc";
or equivalently:
const char* const two_objects = one_object;
Martin