Missing newline in strings passed to printf

Luke Powell luke@lukepowell.net
Fri Nov 10 15:55:00 GMT 2006


Disregard my previous message. I had forgotten that puts() appends a
newline, so in changing the call from printf to puts the correct thing
was done. Apologies for the waste of time.

Luke

On 11/10/2006 09:03 AM, Luke Powell wrote:
> Hello all,
> 
> I'm seeing a rather odd problem in a m68k toolchain I'm running. I'm
> using GCC 4.1.1. The problem occurs in this code:
> 
> printf("Hello, world!\r\n");
> 
> If I look at the string that is actually generated in the objdump of the
> output, I find that the last \n is stripped, leaving only a \r. I've
> tried other equivalent scenarios, giving the following results:
> 
> const char* greeting = "Hello, world!\r\n"; printf(greeting); -> CORRECT
> puts("Hello, world!\r\n") -> CORRECT
> void doit(const char *s){printf(s);} doit("Hello!\r\n"); -> CORRECT
> printf("Hello, world!\n") -> "Hello, world!" (no \n)
> printf("\n") -> putchar(0x0a) -> CORRECT
> 
> I've only seen this problem in my m68k toolchain, the native gcc seems
> to handle it just fine. I am running gcc with only the following
> options: -mcpu32 -g, so I'm not sure that any optimizations would be
> creeping in. I've verified that the preprocessor output still says
> "\r\n" and that the assembler input says only "\r" so this is a compiler
> issue.
> 
> Any ideas or thoughts?
> 
> Luke
> 
> 



More information about the Gcc-help mailing list