Skip to content
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

The compiler optimizes out unused constants marked with the exportc pragma #17681

Closed
japplegame opened this issue Apr 8, 2021 · 5 comments · Fixed by #24546
Closed

The compiler optimizes out unused constants marked with the exportc pragma #17681

japplegame opened this issue Apr 8, 2021 · 5 comments · Fixed by #24546
Assignees
Labels

Comments

@japplegame
Copy link

The compiler must never optimize out constants marked with the expotrc pragma.
For example:

const foo {. exportc .} = 10

Expected C output:

N_LIB_PRIVATE NIM_CONST NI foo = ((NI) 10);

Current output:
Nothing (optimized out)

@metagn

This comment was marked as off-topic.

@Araq
Copy link
Member

Araq commented Apr 9, 2021

No, const should work too.

@japplegame
Copy link
Author

@hlaaftana, look in the corresponding thread: https://forum.nim-lang.org/t/7763
let does not guarantee that the initializing value will be evaluated at compile time and can be successfully placed in the`rodata ' section.

@PMunch
Copy link
Contributor

PMunch commented Apr 9, 2021

If exportc should work for const then I would say codegenDecl should as well. Would probably solve my gripes with #17497

@auxym
Copy link
Contributor

auxym commented Sep 9, 2022

Adding on, if exportc should work on consts, then should we also be able to take the addr of a const, or at least an exported const? If so this is related to this RFC: nim-lang/RFCs#257

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants