checker: allow int i32 to be used interchangeably#25317
checker: allow int i32 to be used interchangeably#25317spytheman merged 1 commit intovlang:masterfrom
Conversation
|
Why is |
|
In a lot of C compilers It used to be quite common to see typedef int bool;
#define true 1
#define false 0Then your code do if (mybool == true) // or more often, `if (mybool)`
{
...
}or whatever, which is all |
|
Alternatively, we can mandate the addition of explicit type casting where necessary in the code, such as |
|
That would be the better thing all around, really, as you cannot guarantee that |
|
can we remove these from the // allow bool & int to be used interchangeably for C functions
if (got.idx() == ast.bool_type_idx
&& expected.idx() in [ast.int_type_idx, ast.int_literal_type_idx, ast.i32_type_idx])
|| (expected.idx() == ast.bool_type_idx
&& got.idx() in [ast.int_type_idx, ast.int_literal_type_idx, ast.i32_type_idx]) {
return
}
exp_sym := c.table.sym(expected)
// unknown C types are set to int, allow int to be used for types like `&C.FILE`
// eg. `C.fflush(C.stderr)` - error: cannot use `int` as `&C.FILE` in argument 1 to `C.fflush`
if exp_is_ptr && exp_sym.language == .c && exp_sym.kind in [.placeholder, .struct]
&& got == ast.int_type_idx {
return
}
I suggest remove these checks, and make explicit type casting in V source code. As BTW: pub enum FileBufferMode {
fully_buffered = C._IOFBF
line_buffered = C._IOLBF
not_buffered = C._IONBF
}need change to pub enum FileBufferMode {
fully_buffered = i32(C._IOFBF)
line_buffered = i32(C._IOLBF)
not_buffered = i32(C._IONBF)
} |
|
Or should we introduce something redecalre the For example: (C.stdio, C.stderr) = &C.FILE |
|
Please do focus on the current PR, and avoid discussing things unrelated to it here. There is https://github.com/vlang/v/discussions and Discord for chatting/discussing other topics. |
This should now just apply to |
Similarly, this should apply to On the V side, now |
That can be a separate proposal/PR, for C globals/consts . |
9772bb2 to
83697f7
Compare
This is 3rd PR to support 64bit/32bit int as PR #25236 is the first one and #25298 is the second one.
Before apply
v fmt -new_int -w .to the whole v codebase, it is need to ease some type check first.This PR allow
i32<=>booland alsoint<=>i32type check.