curimit / SugarCpp

SugarCpp is a language which can compile to C++11.
135 stars 13 forks source link

no way to declare memory allocation for static array inside class #22

Open zxytim opened 11 years ago

zxytim commented 11 years ago
class A
    [static]
    a: int[1000]

    void func()
        a[1] = 2

int main()
    dummy: int = 5

compiled to .h file

#pragma once

class A {
    static int a[1000];

    void func();
};

int main();

and corresponding cpp file

#include "x.h"

void A::func() {
    a[1] = 2;
}

int main() {
    int dummy = 5;
}

but in fact there should have int A::a[1000] in cpp file.

But as I tried like:

class A
    [static]
    a: int[1000]

    void func()
        a[1] = 2

A::a: int[1000]

int main()
    dummy: int = 5

it compiled into .h

#pragma once

class A {
    static int a[1000];

    void func();
};

extern int A::a[1000];

int main();

and .cpp

#include "x.h"

void A::func() {
    a[1] = 2;
}

int A::a[1000];

int main() {
    int dummy = 5;
}

where the extern in .h file is not what I want

curimit commented 11 years ago

Oh! Thank you very much to point out this issue!

I think this issue has been fixed now.