-
Couldn't load subscription status.
- Fork 279
Description
I believe there exists a Problem with the --translate-const-macros option. A macro #define TEST foo() gets translated to pub const TEST: t = foo();.
This does not compile because foo() is a C function and therefore an unsafe binding but no unsafe Block is generated. In addition foo would need to be compiletime const. Which as far as I know is not possible for bindings? And even if that would be possible c2rust would need to be able to check if it really is compiletime const, which it cant if only provided the functions definition.
And last the achieved behavior in Rust differs from the behavior in C.
I think it would be ok to just completely forbid macro translation into a const if the macro expression is a function call?
The only scenario where this would be a bit problematic, is when there exists a function foo and c2rust has access to the implementation of the function and is able to correctly translate it into Rust and check that it can be evaluated at compile time. Than the code could compile with the unsafe block added. But it would still not represent the C behavior as far as I can see. So maybe it is not really a problem.
Test :
test.h
int foo();
#define GET_FOO (foo())
int use_get_foo() {
return GET_FOO;
}transpile flags:
--translate-const-macros