V version: 35cbca9
OS: Windows 10
What did you do?
fn main() {
mut test_arr := [1, 2, 4, 3, 5]
adder(mut test_arr)
}
fn adder(mut array []int) {
for value in array {
// using for loop causes c error
}
// it works when renaming "array" to anything else I want
/* or it works too
for i in 0..array.len {
println(array[i])
}
*/
}
What did you expect to see?
Compile without errors
What did you see instead?
C:\Users\AppData\Local\Temp\v\test.tmp.c: In function 'main__adder':
C:\Users\AppData\Local\Temp\v\test.tmp.c:7892:10: error: '_t72' undeclared (first use in this function)
array * _t72 = array;
^~
C:\Users\AppData\Local\Temp\v\test.tmp.c:7892:10: note: each undeclared identifier is reported only once for each function it appears in
C:\Users\AppData\Local\Temp\v\test.tmp.c: In function '_vinit':
C:\Users\AppData\Local\Temp\v\test.tmp.c:7921:38: warning: integer constant is so large that it is unsigned
_const_math__bits__max_u64 = ((u64)(18446744073709551615));
^~~~~~
C:\Users\AppData\Local\Temp\v\test.tmp.c:7948:409: warning: integer constant is so large that it is unsigned
((u64)(1)), ((u64)(10)), ((u64)(100)), ((u64)(1000)), ((u64)(10000)), ((u64)(100000)), ((u64)(1000000)), ((u64)(10000000)), ((u64)(100000000)), ((u64)(1000000000)), ((u64)(10000000000)), ((u64)(100000000000)), ((u64)(1000000000000)), ((u64)(10000000000000)), ((u64)(100000000000000)), ((u64)(1000000000000000)), ((u64)(10000000000000000)), ((u64)(100000000000000000)), ((u64)(1000000000000000000)), ((u64)(10000000000000000000))}));
The problem is the variable name array, array is a built-in struct. @medvednikov what should we do in this case?
C code looks like:
array * _t72 = array;
array should be in the internal list of reserved names, so an error message can be given.
We just need to add 'array' to c_reserved :)
this feels like a workaround. isn't it possible to make it possible to have as less as possible reserved words?
What do you mean? It's not reserved. It just tells V that in generated C code _v_array should be generated instead of array.
Fixed.
ah ok! nice.