v icon indicating copy to clipboard operation
v copied to clipboard

Ability to export a global symbol as a true (C-level) constant

Open odiroot opened this issue 1 year ago • 0 comments

Describe the feature

C generator should be able to produce extern const on globals. Code should ideally be validated for a possible non-constant initialisation, e.g. value cannot be initialised with a function call.

Use Case

Mostly useful for creating shared libraries in V based on existing C interface provided with relevant headers. My specific use case is creating audio plugins using CLAP standard, where the entry point to the plugin has to be exported as a const C structure.

Proposed Solution

Syntax wise, I'd propose using existing const keyword. E.g.:

__global const name = value

Or:

__global (
  const name = value
)

Where value would either be a default for the type (no explicit value) or custom one but initialised in a const sense.

Other Information

Currently have to work around the lack of this feature by vendoring-in the C headers and modifying them to drop the const requirement.

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

Version used

V 0.4.4 ac2dcc2.74c31a7

Environment details (OS name and version, etc.)

OS: linux, "EndeavourOS Linux"

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

odiroot avatar Feb 14 '24 18:02 odiroot