Article View: borland.public.cppbuilder.nativeapi
Article #17320Re: Problem in deleting file!
From: Remy Lebeau (TeamB)
Date: Sat, 29 Mar 2003 02:07
Date: Sat, 29 Mar 2003 02:07
37 lines
2689 bytes
2689 bytes
"nicolasr" <nicolasrNOSPAMATSIGNgmx.net> wrote in message
news:3e84fa8a@newsgroups.borland.com...
> Is
> char buffer[MAX_PATH+2] = {0};
> equivalent to
> char buffer[MAX_PATH+2] = ""; ?
{0} is a special-case shorthand that has an effect of zeroing out the entire
buffer's memory while initializing it. I just tested both cases, and they
both zeroed out the entire buffer's memory, so I guess functionally they're
the same as far as the generated code from the compiler is concerned. I
don't know what the C++ spec says the official rules are about initializing
fixed-sized character buffers with "", though. I always prefer to use {0}
because it can be applied to structures as well, which "" can't be.
> I read up the strncpy() help. Is it here where the
> double \0 comes from?
Not in this particular situation, no. strncpy() is simply a safer version
of strcpy() which allows you to specify the maximum number of characters to
copy, whereas strcpy() just copies until it reaches a null terminator
regardless of length. By creating the buffer with 2 extra characters and
then stopping the maximum copying just prior to them, I'm letting the
buffer's initialization ensure that there will always be at least 2 null
terminators in the buffer regardless of how many characters are actually
copied into the buffer later.
Gambit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.463 / Virus Database: 262 - Release Date: 3/17/03
Technical Details
Message-ID:
<3e84fd91$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!cyclone.bc.net!newsfeed.media.kyoto-u.ac.jp!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3E8408FF.5040308@alloymail.com> <3e840eac$1@newsgroups.borland.com> <3E842BD0.1060302@alloymail.com> <3e84ad5c$1@newsgroups.borland.com> <3e84b0d4$1@newsgroups.borland.com> <3e84fa8a@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,5fde27ba165b16db X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-03-28 18:02:41 PST From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3E8408FF.5040308@alloymail.com> <3e840eac$1@newsgroups.borland.com> <3E842BD0.1060302@alloymail.com> <3e84ad5c$1@newsgroups.borland.com> <3e84b0d4$1@newsgroups.borland.com> <3e84fa8a@newsgroups.borland.com> Subject: Re: Problem in deleting file! Date: Fri, 28 Mar 2003 18:07:35 -0800 Lines: 39 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 207.175.226.26 Message-ID: <3e84fd91$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1048903057 207.175.226.26 (28 Mar 2003 17:57:37 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!cyclone.bc.net!newsfeed.media.kyoto-u.ac.jp!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail