Re: Cast trap with INI entries compiling C++ extension

From: Date: Thu, 29 Sep 2011 20:23:58 +0000
Subject: Re: Cast trap with INI entries compiling C++ extension
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-55668@lists.php.net to get a copy of this message
Gustavo Lopes wrote:
const char * and char const * are the same (just like const int and int const are the same); what's not the same is char *const.
Andrey Hristov wrote:
it's easy, whatever const is closer to is immutable const char * is a pointer to a const char, because the const is closer to the char than to the pointer. char * const is a const pointer to a char, because the const is closer to the pointer than to the char. Anyway, never used char const *, which will conflict with my explanation :) Best, Andrey
I stand corrected, char const * is the same as const char* [1], so any of them would work for the ini struct. The C++ FAQ Lite recommends reading it right to left [2], but then the leftmost const case is left undefined by the mnemonic, so it isn't valid for all cases, either. I'm also attaching a small program showing the different ways of accessing each of those and the expected warnings so that your favorite compiler can yell at you :) [1] http://www.parashift.com/c++-faq/const-correctness.html#faq-18.9 [2] http://www.parashift.com/c++-faq/const-correctness.html#faq-18.5

Attachment: [text/x-csrc] const.c
« previous php.internals (#55668) next »