From owner-freebsd-hackers@FreeBSD.ORG Thu Feb 25 22:07:20 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E2F24106564A for ; Thu, 25 Feb 2010 22:07:20 +0000 (UTC) (envelope-from matthias.andree@gmx.de) Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by mx1.freebsd.org (Postfix) with SMTP id 300AD8FC1F for ; Thu, 25 Feb 2010 22:07:19 +0000 (UTC) Received: (qmail invoked by alias); 25 Feb 2010 22:07:17 -0000 Received: from f055003018.adsl.alicedsl.de (EHLO mandree.no-ip.org) [78.55.3.18] by mail.gmx.net (mp059) with SMTP; 25 Feb 2010 23:07:17 +0100 X-Authenticated: #428038 X-Provags-ID: V01U2FsdGVkX1/NiZZzOIHNFZMzIqxDhFabee8s94KfxKemmNa929 m6umeUlORMgEpS Received: from merlin.emma.line.org (localhost [127.0.0.1]) by merlin.emma.line.org (Postfix) with ESMTP id 1C1FF9435F; Thu, 25 Feb 2010 23:07:16 +0100 (CET) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= , "Andrey Zonov" References: <983a1cf21002240544s59006035ifbf0ef7eb045e44f@mail.gmail.com> <86eikar7gv.fsf@ds4.des.no> <4B858007.1000008@gmail.com> <86sk8qpfx8.fsf@ds4.des.no> Date: Thu, 25 Feb 2010 23:07:15 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Matthias Andree" Organization: Message-ID: In-Reply-To: <86sk8qpfx8.fsf@ds4.des.no> User-Agent: Opera Mail/10.10 (Linux) X-Y-GMX-Trusted: 0 X-FuHaFi: 0.62 Cc: freebsd-hackers@freebsd.org Subject: Re: 2 bytes allocated problems X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Feb 2010 22:07:21 -0000 Am 24.02.2010, 20:55 Uhr, schrieb Dag-Erling Smørgrav : > Why is there a 0 after the 'i'? Because when you write "abcdefghi", the > compiler actually stores "abcdefghi\0". That's the definition of > "string" in C: a sequence of characters immediately followed by a 0. If > you don't want the 0 there, you have to do something like this: > > char a[9] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' }; char a[9] = "abcdefghi"; suffices. The compiler knows there isn't room for the terminal '\0' and omits it. char a[] = "abcdefghi"; would append the implicit \0 and reserve 10 bytes for a. > but then you don't have a string, just an array of 9 chars. Not that the compiler itself could/would tell the difference after initialization, or that it would even care. It's the library functions that expect strings that care about the \0. Beyond that, I recommend a C book to Andrey. -- Matthias Andree