This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: No error message when format string is passed as variable to printf functions family


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]