Replies: 3 comments
-
The problem with exporting a struct is that many of the types in V don't match types in C. You would be better off declaring a C struct for both to use. |
Beta Was this translation helpful? Give feedback.
0 replies
-
We allow [export] for functions, I think it'd be consistent to allow it for structs. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yes. It will lead to all sorts of errors when the fields don't match any C types, but it could be allowed. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the feature
Currently
[export: "name"]
does not work for structs when exporting C code. I have not tested exporting as a shared library, but I believe that the this is also not supported.I suggest making it possible to specify the name of the struct that should be used when exporting the code/library.
Example:
Would produce a C struct named
MyStruct
instead of the currentvlib__MyStruct
with a double underscore that looks not like a code that I would writeUse Case
I'm writing a library and would like to distribute also its C version for maximum cross-platformism. The library has structs and I thoght that this:
would produce a struct with the name
TheStruct
in the C file, but it actually generates a struct namedmylib__MyStruct
.Proposed Solution
It would be great if the export directive worked with structs because it would make the language more welcoming for people like me that want to develop a library in a language with modern features but also wants the library to work in a wide variety of platforms, and C is the current "de facto cross platform assembly language".
Other Information
Alternative 1:
Allow customization of the module prefix during compilation instead of having the
Example:
<compiler and args> --module-prefix mylib="" --module-prefix utils="utilities_"
Alternative 2
Allow customization of the module prefix with a directive on top of the module keyword.
Example 1:
lib1.v
that would produce a struct named
MyStruct
lib2.v
that would produce a struct named
XMyStruct
lib3.v
that would produce a struct named
mylib_MyStruct
.Acknowledgements
Version used
V 0.3.3 d1f57ea
Environment details (OS name and version, etc.)
OS: linux, "Arch Linux"
Processor: 12 cpus, 64bit, little endian, Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
CC version: cc (GCC) 12.2.1 20230201
getwd: /home/andre/Downloads/vtest
vmodules: /home/andre/.vmodules
vroot: /usr/lib/vlang
vexe: /usr/lib/vlang/v
vexe mtime: 2023-03-09 10:58:59
is vroot writable: false
is vmodules writable: true
V full version: V 0.3.3 d1f57ea
Git version: git version 2.40.0
Git vroot status: Error: fatal: not a git repository (or any of the parent directories): .git
.git/config present: false
thirdparty/tcc status: Error: fatal: detected dubious ownership in repository at '/usr/lib/vlang/thirdparty/tcc'
To add an exception for this directory, call:
Error: fatal: detected dubious ownership in repository at '/usr/lib/vlang/thirdparty/tcc'
To add an exception for this directory, call:
Beta Was this translation helpful? Give feedback.
All reactions