This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: constant string changed
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Phung Nguyen <nhphung at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 6 Oct 2010 17:04:34 +0200
- Subject: Re: constant string changed
- References: <AANLkTikWK4_FLkS1-ut=rgeU2CgDBpKQtWv2UzN+DJdd@mail.gmail.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, Oct 06, 2010 at 09:59:29PM +0700, Phung Nguyen wrote:
> When porting GCC on xc16x, I met a problem with a constant string. The
> following is the C code:
> #include "stdio.h"
>
> int main () {
>
> printf ("c\n");
> }
> And the following is the generated assembly:
> .xc16x
>
> .section .rodata
>
> .LC0:
> .ascii "c\0"
> .section .text
> .align 1
> .global _main
> _main:
> mov [-r0],r1
> mov r1,r0
>
> mov r8,#SOF:.LC0
> calla cc_UC,_puts
> mov r1,[r0+]
> ret
>
> where there is no '\n' in the constant string .LC0 any more. However,
> when I change the string into "%c\n" (with a character passed), the
> constant string .LC0 becomes .ascii "c\12\0"
>
> Is there any idea about this kind of problem? Where did I got the mistake?
Why do you think there is any problem? printf ("c\n") is quivalent
to cheaper puts ("c"), so when optimizing gcc uses the latter instead of
former.
Jakub