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