magic-lang / rock

ooc compiler written in ooc
http://ooc-lang.org/
MIT License
14 stars 4 forks source link

Can we export unmangled global variables ? #76

Closed ghost closed 7 years ago

ghost commented 7 years ago

I would like to do something like

// file.c
const int MY_VAR = -1;

// file.h
extern const int MY_VAR;

Where in .ooc file should I place the definition of MY_VAR: unmangled Int = -1 ? Placing it in the global scope seems to generate only a local variable in the module's load function:

// file.ooc
MY_VAR: unmangled Int = -1

// --> file.c
void file_something_load() {
    ...
    Numbers__Int MY_VAR = -1; // only a local variable !
    ...
}

I guess I could add a plain .c file with just the variable definition (or use unmangled function to return the value), but it seems like easy enough task to be solved via "pure" ooc. And I'm also curious if / how it's possible.

thomasfanell commented 7 years ago

That is weird, since when I try that (placing it in global scope), I get this:

file.c

Numbers__Int MY_VAR;

file-fwd.h

extern Numbers__Int MY_VAR;

and then in file_load()

MY_VAR = -1;
ghost commented 7 years ago

Thanks, I will try that again on the same files I tried before and let you know.

thomasfanell commented 7 years ago

Created a specific issue for variables defined inside a version block. #77