-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problematic macro translation with --translate-const-macros
#803
Comments
--translate-const-macros
* add fix for the problematic macro translation mentioned in the issue * add test for the fix
Thanks for the bug report--I can confirm the problematic behavior. The This issue is subtler than it may appear because the real constraint here is on the Rust side--we cannot generate a We could, then, say "is the Rust code we generate for this macro definition |
Thanks for the feedback. Yes a fully reliable feature like this would need the complex In a concrete use-case it is possibly to work around this by injecting C functions via a build-script like this: int macro_const() {
return MACRO;
} Its only annoying because you have to keep a list of the Macros around. Maybe in the future C2Rust will be able to check for |
I believe there exists a Problem with the
--translate-const-macros
option. A macro#define TEST foo()
gets translated topub const TEST: t = foo();
.This does not compile because
foo()
is a C function and therefore an unsafe binding but nounsafe
Block is generated. In additionfoo
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
transpile flags:
The text was updated successfully, but these errors were encountered: