#80 Merge duplicate strings function is ineffective

open-rejected
None
5
2009-09-27
2004-07-01
No

The 'merge duplicate strings' function is ineffective for
structure arrays.

The following code results in storing "abc" two times in
program memory:

code struct {
char* b;
} c[2]={{"abc"}, {"abc"}};
void main(void){}

On the other hand, the following code stores "abc" only
once in program memory:

code char* code a="abc";
code struct {
char* b;
} c[2]={{"abc"}, {"abc"}};
void main(void){}

So it seems that the 'merge duplicate strings' function
does not work for initialised structure arrays, unless the
same string has already been defined beforehand, like in
the second sample.
The resulting code runs properly in the first case as well,
but it utilises the program memory ineffectively.

SDCC :
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51
/ds400/hc08 2.4.2 (Jun 13 2004) (MINGW32)

bortel.laszlo@ln.matav.hu

Discussion

  • Borut Ražem

    Borut Ražem - 2007-10-18
    • labels: --> 355283
    • milestone: --> 100457
    • assigned_to: nobody --> borutr
    • status: open --> closed-fixed
     
  • Borut Ražem

    Borut Ražem - 2007-10-18

    Logged In: YES
    user_id=568035
    Originator: NO

    Fixed in svn revision #4936.

    Borut

     
  • Patryk

    Patryk - 2007-11-12

    Logged In: YES
    user_id=1788180
    Originator: NO

    Didn't it affect fix #1547512: Redundant strings linked when using sizeof("abc")?

     
  • Borut Ražem

    Borut Ražem - 2007-11-17
    • milestone: 100457 --> 100454
    • status: closed-fixed --> open-rejected
     
  • Borut Ražem

    Borut Ražem - 2007-11-17

    Logged In: YES
    user_id=568035
    Originator: NO

    I reverted the fix since it has a problem in the following case, as reported at https://sourceforge.net/tracker/?func=detail&atid=350599&aid=1547512&group_id=599:

    --8<---------------------
    static code const struct
    {
    unsigned char Length;
    unsigned char String[4];
    } My_str =
    {
    5,
    "abc"
    };
    -->8---------------------

    Fix reverted in svn revision #4966.

    Borut

     
  • Laszlo BORTEL

    Laszlo BORTEL - 2008-01-24

    Logged In: YES
    user_id=1063737
    Originator: YES

    Hi Borut,

    any chance that this old bug of mine will be fixed soon? It causes me significant headache in my project.

    Regards,
    Laszlo

     
  • Borut Ražem

    Borut Ražem - 2008-02-09

    Logged In: YES
    user_id=568035
    Originator: NO

    Hi Laszlo,

    I can't promise anything. I already tried to fix it, but the fix had a side effect, so I reverted the fix.

    Borut

     
  • Philipp Klaus Krause

    Anyway this is just about code size efficiency, thus a feature request, not a bug.

     
  • Philipp Klaus Krause

    • labels: 355283 -->
    • milestone: 100454 -->
     

Log in to post a comment.