vlang/c2v

if define problem

MatejMagat305 opened this issue · 1 comments

it is silly error, but in complicate project can be seriostly problém ...

describe problem

I was only for fun transleted medium project and I notice that, it is ignored #if defined(...)

what I do

translated with :
v -os cross translate ./define.c
symplified code:

#if defined(__APPLE__) || defined(__MACOSX)
const u = 1;
#elif defined(__ANDROID__)
const u = 2;
#elif defined(_WIN32)
const u = 3;
#elif defined(__linux__)
const u = 4;
#else
#define const u = 5 ;
#endif

what I expected

multiple files for os or warning or error

what I see

one file with

[translated]
module main

[export: 'u']
const (
	u = 4
)

and no error

That's not an error - that's the way C works. The C preprocessor would reduce the C code down to just

const u = 4;

when compiled on Linux, and that's all c2v would see in the AST, so that's exactly what was translated.

The only way to "fix" it would be for V to parse the C code first, which is unlikely to happen any time soon.