-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Compiler complains about not using module that contains only use its C bindings or global variables #23377
Comments
In your second program did you try module term
import driver.gop
pub fn init_term() {
width := gop.framebuffer.width
} |
Hello, thanks for your reply. The second program (module term) is used with the first program (module gop). For global variables, there is no way to set them to public. We can probably assume it is always public. Because I can use the module term
pub fn init_term() {
width := framebuffer.width // ok
} But I can't access module term
import driver.gop
pub fn init_term() {
width := gop.framebuffer.width // error: undefined ident: `driver.gop.framebuffer`
} So my temporary solution is is the method 1, which is to call As for the I also realized that this global variable issue may have something to do with how V manages global variables, i.e. they are available to all modules by default. So this issue may need to be split. Looking forward to your suggestions. |
Try structs module gop
pub struct FrameBuffer {
pub:
fb limine.Framebuffer
} and then: module term
import driver.gop
pub fn init_term() {
fb := gop.FrameBuffer{}
println('{fb.fb.width}') // limine.Framebuffer.width should be public, if global make another struct
}
|
Thanks for the reply, but I do need to use global variables because there is the I'll briefly describe what happened. For global variables, I was able to use them without importing them, probably because that's the way the V was designed. But for C bindings, if you don't import the module that declares it, you get compiler errors like |
In https://github.com/vlang/v/blob/master/vlib/sokol/f/f.v there are imports of C modules like this: import sokol.c as _ Seems to me to load the C definitions and to prevent the module marked as not used. Try this. |
Describe the bug
Compiler complains about not using module that contains only use its C bindings or global variables.
Reproduction Steps
I have a module that use a global variable in another module:
But the compiler warns that module 'gop (driver.gop)' is imported but never used.
The C bindings are in same situation. For example, I have a module that contains C bindings, I can use the C functions defined in it in other modules by importing it:
However, the compiler will warn that module 'log' is imported but never used.
Attempts
For global variables, I can create a wrapper function that returns the global variable:
And use it in other modules:
For C bindings, perhaps a good practice is to make a V-function wrapper for this c-function:
But the variable parameter of the V's function depends on dynamic arrays. Since I'm doing bare-metal development, the generated C code that uses many platform-dependent symbols (e.g. fwrite, stdout) is unusable.
Possible Solution
The compiler should be able to detect the use of global variables or C bindings in a module without warning that the module was imported but never used.
What's more, It would be nice if I could create a V function wrapper and pass variable arguments directly to the C function without create array.
V version
V 0.4.9 3953445
Environment details (OS name and version, etc.)
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.
Huly®: V_0.6-21808
The text was updated successfully, but these errors were encountered: