#36 structs doesn't permits arrays

compiler
closed-rejected
NBC (24)
5
2009-01-18
2007-09-26
Anonymous
No

When you try to create an struct like this:

struct s {
int a[10];
}

it simply say that:

# Error: ';' expected
File "/home/lab/test.nxc" ; line 14
# int a[1
#----------------------------------------------------------
# Error: Invalid variable declaration (])
File "/home/lab/test.nxc" ; line 16
#
#----------------------------------------------------------

So, i deduce that it's not posible for the compiler to understand this construction.

It's actually this way?

PD: Sorry my english.

Discussion

  • John Hansen

    John Hansen - 2007-09-26

    Logged In: YES
    user_id=661666
    Originator: NO

    You cannot specify a size for arrays in structs. Their size is required to be a run-time configuration rather than a compile-time configuration. Just leave off the size and then on the instance of the struct you can initialize the array to a certain size using ArrayInit(myStruct.a, 0, 10);

    Here's the right syntax:

    struct s {
    int a[];
    };

    task main() {
    s myStruct;
    ArrayInit(myStruct.a, 0, 10);
    }

    John Hansen

     
  • John Hansen

    John Hansen - 2007-09-26
    • status: open --> closed-rejected
     
  • Nobody/Anonymous

    • status: closed-rejected --> open-rejected
     
  • Nobody/Anonymous

    Logged In: NO

    All right. Thank you very much :-D, and sorry for my error.

     
  • John Hansen

    John Hansen - 2009-01-18
    • status: open-rejected --> closed-rejected
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks