public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Sam Lauber" <sam124@operamail.com>
To: "Dave Korn" <dave.korn@artimi.com>, gcc@gcc.gnu.org
Subject: RE: Unomitted frame pointers
Date: Sat, 11 Dec 2004 02:44:00 -0000	[thread overview]
Message-ID: <20041211024445.57C2E23CE8@ws5-3.us4.outblaze.com> (raw)

We would end up with two copies of the string. #defines are preprocessed, so it would expand to the second thing. The _safe_ way to do it is

char str = "Hello World!\n";
write(2, str, strlen(str)-1);

Then we can be sure that it refers to the same physical address in RAM. "Two copies" is when the strings are positioned at diffrent non-overlapping addresses. Though optimization and inlining might mess it up.

Samuel Lauber

----- Original Message -----
From: "Dave Korn" <dave.korn@artimi.com>
To: "'jlh'" <jlh@gmx.ch>, "'Thomas R. Truscott'" <trt@cs.duke.edu>
Subject: RE: Unomitted frame pointers
Date: Fri, 10 Dec 2004 16:23:59 -0000

> 
> > -----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....

-- 
_____________________________________________________________
Web-based SMS services available at http://www.operamail.com.
From your mailbox to local or overseas cell phones.

Powered by Outblaze

             reply	other threads:[~2004-12-11  2:44 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-11  2:44 Sam Lauber [this message]
2004-12-11 15:40 ` Nathan Sidwell
2004-12-11 15:45 ` Andreas Schwab
  -- strict thread matches above, loose matches on Subject: below --
2004-12-11 16:29 Sam Lauber
2004-12-12  1:33 ` Ian Lance Taylor
2004-12-11 16:26 Sam Lauber
2004-12-11 16:42 ` Nathan Sidwell
2004-12-12  0:09 ` Peter Barada
2004-12-11 16:15 Sam Lauber
2004-12-11 17:00 ` Eric Botcazou
2004-12-11 18:10 ` Robert Dewar
2004-12-13  6:16   ` Ranjit Mathew
2004-12-13 14:22     ` Robert Dewar
2004-12-13 23:36     ` Ben Elliston
2004-12-11  2:37 Sam Lauber
2004-12-10 15:44 Thomas R. Truscott
2004-12-10 16:05 ` jlh
2004-12-10 16:25   ` Dave Korn
2004-12-10 16:30     ` Nathan Sidwell
2004-12-10 16:41       ` Dave Korn
2004-12-10 17:54         ` Nathan Sidwell
2004-12-10 16:33     ` Andreas Schwab
2004-12-10 16:40       ` Dave Korn
2004-12-10 16:55       ` Thomas R. Truscott
2004-12-10 17:26         ` Paul Brook
2004-12-11 11:53           ` Kai Henningsen
2004-12-10  5:26 Sam Lauber
2004-12-10  7:22 ` Eric Botcazou
2004-12-10  9:08 ` Richard Guenther

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041211024445.57C2E23CE8@ws5-3.us4.outblaze.com \
    --to=sam124@operamail.com \
    --cc=dave.korn@artimi.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).