[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-libc-dev] Re: snprintf bug ?
From: |
Dmitry K. |
Subject: |
Re: [avr-libc-dev] Re: snprintf bug ? |
Date: |
Fri, 14 Oct 2005 14:23:48 +1100 |
User-agent: |
KMail/1.5 |
On Thursday 13 October 2005 21:46, Russell Strong wrote:
> Hi,
>
> The following is the full source and Makefile for my snprintf bug
[...]
> static void update_heading_string (int hdg_reading)
> {
> long delta = 0;
> unsigned char i;
> static int base_hdg = 0;
> // static char heading_tmp[5]; // This works
> char heading_tmp[5]; // This doesn't work
[...]
> snprintf (heading_tmp, 5, "%04X", base_hdg);
[...]
> int main () __attribute__ ((naked));
> int main ()
> {
[...]
> update_heading_string (heading_byte_1 * 256 + heading_byte_2);
[...]
> OPTIMIZE = -O2
[...]
I have look yours program by two compilers: 3.3 and 4.0.
Modern compiler (4.0) make function 'update_heading_string'
as inline function (with -O2). This reduce code size (call
is single) and speed up run.
You have exclude frame pointer (r28/r29) initialization
by defining 'naked' for main.
But with automatic string 'heading_tmp' this is not work:
frame pointer is used as base address. Result is writing
to random place. With static string all works:
address is absolute.
With old compiler it works also: 'update_heading_string'
is not inlined, frame pointer is initialized in prologue
of 'update_heading_string'.
I do not known is this bug single, I have not try to run.
Regards,
Dmitry.
Re: [avr-libc-dev] snprintf bug ?, Bernard Fouché, 2005/10/13