-
-
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
Proper cast of <string>.str
to char *
#19623
Comments
// main.v
import os
#flag -I@VMODROOT
#flag @VMODROOT/c.o
#include "c.h"
fn C.hello(&i8) // ==> use i8
fn main() {
arg := os.args[1] or { 'World' }
C.hello(arg.str)
}
I think, for now, it's up to the programmer to properly use the corresponding types for V, C interactions |
V temporarily does not seem to deal with the type correspondence of V to C |
Yep. But it might be not too hard to add a cast in the cgen if the target type differs like |
For C code, V currently does only "insert", not "parse", so the amount of work for this conversion... |
Not too much 😉 |
Exactly as it should be. Making the V compiler do such conversions automatic, but only in some edge cases, is very brittle, and makes its behavior hard to predict and use. |
Describe the bug
Using
.str
to cast astring
type variable to a C *char results in a compilation error when compiling with (-cc gcc
or-cc clang
) and-cstrict
. Currently, it's required that the programmer writes the typecast&char(<string>.str)
explicitly to have it working.Reproduction Steps
Following uses the layout:
Works
Errors
Expected Behavior
Works when compiling with mentioned flags.
Current Behavior
builder error:
Possible Solution
No response
Additional Information/Context
Might be more of a FR than a bug. Also, I'm not entirely sure what the downsides of an implementation might be, but I'm open to read about them.
V version
-
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.
The text was updated successfully, but these errors were encountered: