Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:55668 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5470 invoked from network); 29 Sep 2011 20:18:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Sep 2011 20:18:15 -0000 Authentication-Results: pb1.pair.com header.from=keisial@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=keisial@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: keisial@gmail.com X-Host-Fingerprint: 74.125.82.170 mail-wy0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:61917] helo=mail-wy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 62/00-05328-682D48E4 for ; Thu, 29 Sep 2011 16:18:14 -0400 Received: by wyg30 with SMTP id 30so409202wyg.29 for ; Thu, 29 Sep 2011 13:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type; bh=gcfCOIukM8cCWC+g0TSX1LZWq2EfKWcf5i8IbECODnA=; b=MojqN2tgMsZpgKl+nNfiy9MDNqWPiz48fXp5/sUFVcgFZ+nVwGjvyxu8gasHzAX+Wo GgPn5MXJR/uH29gW1y59TkuVrDhqtqzbR4fRg8Jt5h0FQSb6DY+sIj1KXp5wDP6k1g7o 1g9018Vp+u6e9OeNA3S+oIkOdS8pLzLEYC550= Received: by 10.216.132.198 with SMTP id o48mr3324166wei.7.1317327489641; Thu, 29 Sep 2011 13:18:09 -0700 (PDT) Received: from [192.168.1.26] (217.Red-88-13-201.dynamicIP.rima-tde.net. [88.13.201.217]) by mx.google.com with ESMTPS id fa3sm4560152wbb.3.2011.09.29.13.17.48 (version=SSLv3 cipher=OTHER); Thu, 29 Sep 2011 13:17:49 -0700 (PDT) Message-ID: <4E84D3DE.8010805@gmail.com> Date: Thu, 29 Sep 2011 22:23:58 +0200 User-Agent: Thunderbird MIME-Version: 1.0 To: Andrey Hristov CC: Gustavo Lopes , internals@lists.php.net References: <4E848B31.2030501@gmail.com> <4E84A73E.8030601@gmail.com> <4E84B4DE.3070904@hristov.com> In-Reply-To: <4E84B4DE.3070904@hristov.com> Content-Type: multipart/mixed; boundary="------------050608030903050504080902" Subject: Re: [PHP-DEV] Cast trap with INI entries compiling C++ extension From: keisial@gmail.com ("=?UTF-8?B?w4FuZ2VsIEdvbnrDoWxleg==?=") --------------050608030903050504080902 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------050608030903050504080902 Content-Type: text/x-csrc; name="const.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="const.c" int main() { const char* char_const1 = "ABC"; char_const1[0] = 'B'; /* Error */ char_const1 = "DEF"; /* Ok */ char const* char_const2 = "ABC"; char_const2[0] = 'B'; /* Error */ char_const2 = "DEF"; /* Ok */ char * const ptr_const = "ABC"; ptr_const[0] = 'B'; /* Ok */ ptr_const = "DEF"; /* Error */ char const * const const_const = "ABC"; const_const[0] = 'B'; /* Error */ const_const = "DEF"; /* Error */ return 0; } --------------050608030903050504080902--