From: SourceForge.net <no...@so...> - 2010-06-11 17:23:48
|
Bugs item #2024627, was opened at 2008-07-22 15:43 Message generated for change (Comment added) made by jpa- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=2024627&group_id=599 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: pic14 target Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Stefan Dimitrov (stedi) Assigned to: Raphael Neider (tecodev) Summary: PIC, Static variables problem Initial Comment: Using SDCC for PIC16F877 microcontroller. There is a bug with static variables. In generated assembly code, the 'main' procedure does not initialize static variables. Command: sdcc -S -mpic14 -p16f877a main.c SDCC version: msc51/gbz80/z80/avr/ds390/pic16/pic14/TININative/ xa51/ds400/hc08 2.0.8 #5117 (Mar 23 2008) (MINGW32) E-mail: stf...@ma... ---------------------------------------------------------------------- Comment By: jpa (jpa-) Date: 2010-06-11 20:23 Message: Hm, file attaching failed, here it is as text: #include <pic16f689.h> static char global_test = 10; /* This is initialized correctly */ void foo() { static char local_test = 20; /* This is not initialized at all */ PORTA = global_test; PORTC = local_test; } void main() { TRISA = 0; TRISC = 0; foo(); while(1); } ---------------------------------------------------------------------- Comment By: jpa (jpa-) Date: 2010-06-11 20:20 Message: I think I have the same problem. Global variables are initialized correctly, but local static variables are not. The local static variables are also marked in assembler output as udata. See the attached file sdcc-test.c, which I compiled using: sdcc -mpic14 -p16f689 sdcc-test.c I'm using: SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.9.0 #5416 (Jan 10 2010) (UNIX) ---------------------------------------------------------------------- Comment By: Stefan Dimitrov (stedi) Date: 2008-07-28 16:43 Message: Logged In: YES user_id=2155117 Originator: YES I don`t think this will be very usefull, but just in case here is the full source code of my program + Makefile used to generate the objects. As you will see, if I use 'dpos' as static variable, my 'display()' procedure does not work. File Added: static.rar ---------------------------------------------------------------------- Comment By: Stefan Dimitrov (stedi) Date: 2008-07-28 16:41 Message: Logged In: YES user_id=2155117 Originator: YES I don`t think this will be very usefull, but just in case here is the full source code of my program + Makefile used to generate the objects. As you will see, if I use 'dpos' as static variable, my 'display()' procedure does not work. File Added: static.rar ---------------------------------------------------------------------- Comment By: Raphael Neider (tecodev) Date: 2008-07-26 23:49 Message: Logged In: YES user_id=1115835 Originator: NO Oh, I realized your problem: Initializers for static variables are not emitted in the .asm file at all... This needs to be fixed. Thanks for the report! Workaround: Use initialized global variables for now: int foo(void) { static int bar = 42; return bar++; } becomes /*static*/ int __foo_bar = 42; int foo(void) { return __foo_bar++; } ---------------------------------------------------------------------- Comment By: Raphael Neider (tecodev) Date: 2008-07-26 23:35 Message: Logged In: YES user_id=1115835 Originator: NO main() never initializes static variables, __sdcc_gsinit_startup() from the library module idata.[co] does, if the project links against the libsdcc.lib (the default behaviour without -c or -S). Could you post more information about the problem? Do you observe runtime errors? Can you upload a failing source file? If there is a problem, just reopen this item and post more info. Kind regards, Raphael ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=2024627&group_id=599 |