🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #3762

Re: What happens when ...

#3762
From: Michel Leunen
Date: Sat, 06 May 2006 16:55
29 lines
1748 bytes
JD wrote:

> What's actually happening internally when a local variable is
> declared as such:
> 
>     char *ptr = "XXX";

(Besides what others already told you)
The compiler allocates an array of 4 const characters (3 chars + the \0 
byte) and makes ptr points to the first character in this array. For 
backward compatibility, C++ allows you to not prefix your pointer with 
const. Actually,

char* ptr = "XXX";

is silently converted to:

const char* ptr = "XXX";

but it's perfectly legal code although deprecated.

Michel
-- 
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
http://www.leunen.com/
----------------------------------------
Technical Details
Message-ID: <445cd44f$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <445cbd5d$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,2f21d80b956d055f
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Sat, 06 May 2006 18:55:13 +0200
From: Michel Leunen <nospam@noreply.please>
Organization: www.leunen.com
User-Agent: Thunderbird 1.5.0.2 (Windows/20060308)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: What happens when ...
References: <445cbd5d$1@newsgroups.borland.com>
In-Reply-To: <445cbd5d$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 81.243.104.132
Message-ID: <445cd44f$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1146934351 81.243.104.132 (6 May 2006 09:52:31 -0700)
Lines: 29
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail