From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23992 invoked by alias); 10 Dec 2004 16:25:46 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 23864 invoked from network); 10 Dec 2004 16:25:39 -0000 Received: from unknown (HELO NUTMEG.CAM.ARTIMI.COM) (217.40.111.177) by sourceware.org with SMTP; 10 Dec 2004 16:25:39 -0000 Received: from mace ([192.168.1.25]) by NUTMEG.CAM.ARTIMI.COM with Microsoft SMTPSVC(6.0.3790.211); Fri, 10 Dec 2004 16:23:59 +0000 From: "Dave Korn" To: "'jlh'" , "'Thomas R. Truscott'" Cc: Subject: RE: Unomitted frame pointers Date: Fri, 10 Dec 2004 16:25:00 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit In-Reply-To: <41B9C91A.8020405@gmx.ch> Message-ID: X-OriginalArrivalTime: 10 Dec 2004 16:23:59.0906 (UTC) FILETIME=[A792B820:01C4DED4] X-SW-Source: 2004-12/txt/msg00364.txt.bz2 > -----Original Message----- > From: gcc-owner On Behalf Of jlh > Sent: 10 December 2004 16:05 > To: Thomas R. Truscott > > Off-topic, but the hello.c program does: > > write(2, "Hello World!\n\0", 16); > > The string length is 15, not 16. > > 15 is what gets allocated for storing the string (counting > the additional \0 that always gets appened to string constants). > But neither the explicit nor the implicit \0 should be printed > to the console, so the call should definitely read: > > write(2, "Hello World!\n", 13); > > jlh Except of course on targets where '\n' expands to a two char CR-LF combination. So really the safe way to code this is #define HELLOSTRING "Hello World!\n" write (2, HELLOSTRING, strlen(HELLOSTRING)-1); and let the compiler statically compute the string length for you at compiletime. The #define is used to make sure we don't end up with two copies of the string that get out of sync, as would be bound to happen sooner or later if we wrote write (2, "Hello World!\n", strlen("Hello World!\n")-1); cheers, DaveK -- Can't think of a witty .sigline today....