#426 result of sizeof for 2d arrays is wrong

closed-fixed
None
5
2013-05-25
2002-12-28
Anonymous
No

Sizeof calculate a wrong arraysize for a "open" array.
The version is SDCC Version 2.3.2

This sample shold return 6 , not 4.

----------------------------
volatile unsigned char test;

code unsigned char buf[][2]={{0,1},{2,3},{4,5}};

main()
{

test=sizeof(buf);

}
----------------------------

0038 75 08 04 122 mov _test,#0x04
003B 123 00101$:
003B 22 124 ret
125 .area CSEG
(CODE)
003C 126 _buf:
003C 00 127 .db #0x00
003D 01 128 .db #0x01
003E 02 129 .db #0x02
003F 03 130 .db #0x03
0040 04 131 .db #0x04
0041 05 132 .db #0x05

Discussion

  • Nobody/Anonymous

    Logged In: NO

    I think that the function
    checkDecl (symbol * sym, int isProto)
    in SDCCsymt.c is the Problem.
    This function inserts the second dimension in the open
    dimenion
    instead of the count of elements.

    The sizeof this array is 4 but shold be 2.

    code unsigned char tmp1[][2]={{0,1}};

    tmp1[][2]={{1,2}};
    The cdb-line is
    S:G$tmp1$0$0({4}DA2,DA2,SC:U),D,0,0

    the same for
    code unsigned char tmp2[][4]={{0,1,1,3},{2,3,3,3}};
    S:G$tmp2$0$0({16}DA4,DA4,SC:U),D,0,0

    g.fink@gmx.net

     
  • Bernhard Held

    Bernhard Held - 2003-01-11
    • milestone: --> fixed
    • assigned_to: nobody --> johanknol
    • status: open --> closed-fixed
     
  • Bernhard Held

    Bernhard Held - 2003-01-11

    Logged In: YES
    user_id=203539

    Fixed by Johan. The bug was also exposed in float.c of the
    regression tests.

     

Log in to post a comment.