Hello all,

First of all thanks and congratulations for providing us all such capable open source compiler for small devices.

I experienced some strange behavior when trying to assign values to dereferenced pointers in my programs. I decided to post here since I could not find similar messages in the lists, forums, bug reports, Changelog, etc. My apologies if this regards to some previously solved /reported problem (or problem with my code).

Here follows the relevant code:

void main(void)
     unsigned char c = 0x34;
     unsigned char *p;

     p = &c;
     p = 0x12;


There is no error messages when compiling but if I test *p after the last line of code above it seems to be neither 0x12 nor 0x34! If I remove the last line then both *p and c seem to store the same 0x34 value.

I tried to check the generated asm file, and I had a look at gptrput1.c but I could find no mistakes.

My target is the PIC18F1220, programmed using ICD2 (through serial port) and Piklab.

More details about my setup bellow:

$ sdcc -v
SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.6.3 #4555 (Jan  4 2007) (UNIX)

$ gpasm -v
gpasm-0.13.3 beta

$ piklab -v
Piklab version: 0.12.2 (rev. distribution)
Qt: 3.3.6
KDE: 3.5.5
Piklab: 0.12.2

Piklab compiling log shows:
sdcc -mpic16 -p18f1220 -V --debug -I/directory-here/ -Wl-opointertest.hex -Wl-m -Wl-ainhx32 pointertest.c
message: using default linker script "/usr/share/gputils/lkr/18f1220.lkr"
+ "/usr/local/bin/sdcpp" -nostdinc -Wall -std=c99 -I"/home/guerra/Desktop/ecobe-firmware/" -Dpic18f1220 -D__18f1220 -DSTACK_MODEL_SMALL -obj-ext=.o -DSDCC_MODEL_SMALL -DSDCC=263 -DSDCC_pic16 -D__pic16 -I"/usr/local/bin/../share/sdcc/include/pic16" -I"/usr/local/share/sdcc/include/pic16" -I"/directory-here/"  "pointertest.c"
+ "gpasm" -DSDCC_MODEL_SMALL -Dpic18f1220 -D__18F1220 -DSTACK_MODEL_SMALL -g -c "pointertest.asm" -o "pointertest.o"
+ "gplink" -I"/usr/local/bin/../share/sdcc/lib/pic16" -I"/usr/local/share/sdcc/lib/pic16"  -opointertest.hex -m -ainhx32  -w -r -o pointertest pointertest.o  crt0i.o pic18f1220.lib libsdcc.lib

Any help appreciated.

Rodrigo da Silva Guerra
PhD Student

Department of Adaptive Machine Systems
Graduate School of Engineering
Osaka University - Japan