#1675 PIC16: global const struct initializing problem

closed-fixed
5
2013-05-25
2010-08-07
strobla
No

Dear Raphael, dear sdcc-developers,

my USB bootloader project is not compileable any more after revision r5894 including current revision r5917.
If I revert the patch for src/pic16/glue.c from revision 5893:5894 all is working again.
(It is possible, that my code is not valid as gcc compiled code fails with:
cc -DUSE_GCC -O2 -c -o sub.o sub.c
sub.c:3: error: invalid application of ‘sizeof’ to incomplete type ‘const unsigned char[]’
make: *** [sub.o] Fehler 1
)

And: you are doing a great job. Thanks for developing sdcc.

Regards, Strobl Anton

== sub.c =====================================
#include "sub.h"
const unsigned char mystring[] = { sizeof(mystring), 0x31, 0x32, 0x33, 0x34 };

== sub.h =====================================
extern const unsigned char mystring[];

== main.c ====================================
#pragma stack 0xD00 256
#include <pic18fregs.h>
#include <pic18f25j50.h>
#include "sub.h"
#include <stdio.h>

void main(void)
{
unsigned char i;
for (i=0; i< mystring[0]; i++) {
printf ("%s\n", mystring[i] );
};
}

======== log output =========================
current release r5917:

/usr/bin/sdcc_test -mpic16 -p18f25j50 --fomit-frame-pointer --obanksel=2 --opt-code-size --optimize-cmp --optimize-df -I /usr/share/gptuils/lkr -I /usr/share/sdcc/include/pic16 -c -o main.o main.c
sub.h:2: error 66: attempt to allocate variable of unknown size 'str0'
make: *** [main.o] Fehler 1

with revert patch (src/pic16/glue.c / Revision 5893):

/usr/bin/sdcc -mpic16 -p18f25j50 --fomit-frame-pointer --obanksel=2 --opt-code-size --optimize-cmp --optimize-df -I /usr/share/gptuils/lkr -I /usr/share/sdcc/include/pic16 -c -o main.o main.c
/usr/bin/sdcc -mpic16 -p18f25j50 --fomit-frame-pointer --obanksel=2 --opt-code-size --optimize-cmp --optimize-df -I /usr/share/gptuils/lkr -I /usr/share/sdcc/include/pic16 -c -o sub.o sub.c
/usr/bin/sdcc --fomit-frame-pointer --obanksel=2 --opt-code-size --optimize-cmp --optimize-df --use-crt=crt0i.o -Wl-s18f25j50.lkr,-m -mpic16 -p18f25j50 \ main.o sub.o -o test.hex -llibio18f25j50.lib -llibc18f.lib

Discussion

  • strobla
    strobla
    2010-08-07

    small project to demonstrate problem

     
    Attachments
  • Raphael Neider
    Raphael Neider
    2010-08-16

    • milestone: --> fixed
    • status: open --> closed-fixed
     
  • Raphael Neider
    Raphael Neider
    2010-08-16

    SDCC incorrectly bailed out with the above error on the EXTERN declaration of mystring; fixed in r5933.

    By the way, according to my copy of the C standard (draft N1336, Sect. 6.7.8.22), the array has incomplete type until the end of the initializer list, so using sizeof(mystring) during the initialization of mystring is invalid (even if SDCC magically produces correct code).

    You should either declare mystring as
    const unsigned char mystring[5] = { sizeof(mystring), 0x31, 0x32, 0x33, 0x34 };
    or avoid sizeof() via
    const unsigned char mystring[] = { 5, 0x31, 0x32, 0x33, 0x34 };

    Best regards

    Raphael

     
  • Raphael Neider
    Raphael Neider
    2012-02-12

    • assigned_to: nobody --> tecodev