janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.51k stars 227 forks source link

Cannot embed when compiling in MSVC because 'near' is a C keyword #108

Closed Ruin0x11 closed 5 years ago

Ruin0x11 commented 5 years ago

When trying to embed the output janet.c into a program compiled by MSVC, these errors occur.

e:\build\janet/janet.c(5559): error C2513: 'int': no variable declared before '=' [E:\build\cshiori\bin\shiori.vcxproj]
e:\build\janet/janet.c(5560): error C2059: syntax error: ',' [E:\build\cshiori\bin\shiori.vcxproj]
e:\build\janet/janet.c(5561): error C2059: syntax error: ')' [E:\build\cshiori\bin\shiori.vcxproj]
e:\build\janet/janet.c(5563): error C2059: syntax error: ',' [E:\build\cshiori\bin\shiori.vcxproj]

It's because of this code.

https://github.com/janet-lang/janet/blob/41bb6a9833cbb06ff1b83c10b42e446330eadd21/src/core/emit.c#L241-L246

near is a reserved C keyword in some compilers.

bakpakin commented 5 years ago

What version of MSVC are you using? I have only tested on 2017. Will Janet compile if near is changed to another identifier?

Ruin0x11 commented 5 years ago

Yes, it will compile if it is renamed to e.g. nearr. I tested on 2017 also.

bakpakin commented 5 years ago

Ah, makes sense. The amalgamated build will include windows.h near the top, which will define near and far macros.

bakpakin commented 5 years ago

The latest master has the suggested fix as of commit a303704a7d8eca79624eb79ebcdb12df871ec7c9. I will work on adding tests for the amalgamated source to the CI.