#20 translating Array of zero length

Feature request
closed
nobody
None
5
2006-01-03
2005-12-28
camelguo
No

It seems that cilly.asm.exe doesn't translate the
Arrags of Length zero of GCC extension option.

My example is following:

struct line
{
int length;
char contents[];
};

int
main(void)
{
int this_length=1;
struct line* thisline=(struct line*)malloc(sizeof
(stuct thisline+this_length));
memset(thisline,0,sizeof(struct
thisline+this_length));
thisline->length=this_length;
return 0;
}

The command I used to compile the above is the
following:
$tmcc -E -B Arrays_Zero.c > Arrays_Zero.i
$cilly.asm.exe --out Arrays_Zero.cil.c Arrays_Zero.i
$tmcc -g -c Arrays_Zero.cil.c -o Arrays_Zero.o

The cil I used is the newest version.

The error is caused by the third command and it is the
following:
"Array_Zero.c" line:6 error: the size of an array
must be greater than zero
char contents[0];

tmcc.exe: tmcfe command failed

I wonder whether or not the cil can translate zero
length arrays of gcc extension options and How I can
achieve it.

Thanks a lot!

Discussion

  • camelguo
    camelguo
    2005-12-28

    • summary: processing Arrags of Length zero --> translating Array of zero length
     
  • camelguo
    camelguo
    2005-12-28

    Logged In: YES
    user_id=1413983

    I am sorry that the struct line definition is the following
    not the above

    struct line
    {
    int length;
    char contents[];
    };

     
  • camelguo
    camelguo
    2005-12-28

    Logged In: YES
    user_id=1413983

    ?? What happened with sourceforge, why always remove 0!!

    struct line
    {
    int length;
    char contents[0];
    };

     
  • Matt Harren
    Matt Harren
    2006-01-03

    Logged In: YES
    user_id=1278428

    I'm not sure what you want it translated to. You can write
    code to do the conversion yourself: change the length of the
    TArray type to "None" for char contents[], or "Some(integer
    0)" for char contents[0]. If you want more help writing a
    visitor, write to the mailing list. There may also be
    someone on the list with experience with tmcc.

     
  • Matt Harren
    Matt Harren
    2006-01-03

    • status: open --> closed