This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Unomitted frame pointers
- From: "Sam Lauber" <sam124 at operamail dot com>
- To: "Nathan Sidwell" <nathan at codesourcery dot com>, gcc at gcc dot gnu dot org
- Date: Sat, 11 Dec 2004 17:25:55 +0100
- Subject: Re: Unomitted frame pointers
Do you know about macro expansion? CPP would make it seperate strings. So there would be (simplified);
.LC0:
.string "Hello World!\n"
.LC1:
.string "Hello World!\n"
main:
; push LC0 into strlen
push #.LC0, (%eax)
call strlen
; push LC1 into write
push #.LC1, (%ebx)
...
It automatically happens, and I don't know of any way to avoid cpp from macro-expanding it to that. Though inlining would reduce it to the C code
int main(void)
{
char str1 = "Hello World!\n";
char str2 = "Hello World!\n";
int str_len = 0;
while (*str1++ != "\0")
str_len++;
write(2, str2, str_len);
}
embedding strlen inside main. Or even more optimization
int main(void)
{
write(2, "Hello World!\n", 13);
}
which is back where we started.
Samuel Lauber
----- Original Message -----
From: "Nathan Sidwell" <nathan@codesourcery.com>
To: "Sam Lauber" <sam124@operamail.com>
Subject: Re: Unomitted frame pointers
Date: Sat, 11 Dec 2004 15:40:38 +0000
>
> Sam Lauber wrote:
> > 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
> Why do you think you'd get two copies of the string?
>
> >
> > char str = "Hello World!\n";
> type mismatch error
>
> > write(2, str, strlen(str)-1);
> off by one error
>
> nathan
> -- Nathan Sidwell :: http://www.codesourcery.com ::
> CodeSourcery LLC
> nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
--
_____________________________________________________________
Web-based SMS services available at http://www.operamail.com.
From your mailbox to local or overseas cell phones.
Powered by Outblaze