cgen: fix ARR_LEN

pull/4166/head
Alexander Medvednikov 2020-03-31 17:16:12 +02:00
parent 9d630dff30
commit f98cc9c017
3 changed files with 5 additions and 5 deletions

View File

@ -284,8 +284,8 @@ struct Foooj {
fn test_fixed() {
mut nums := [4]int
x := nums[1..3]
assert x.len == 2
//x := nums[1..3]
//assert x.len == 2
assert nums[0] == 0
assert nums[1] == 0
assert nums[2] == 0

View File

@ -1575,9 +1575,9 @@ fn (g mut Gen) index_expr(node ast.IndexExpr) {
}
else if sym.kind == .array_fixed {
// Convert a fixed array to V array when doing `fixed_arr[start..end]`
g.write('array_slice(new_array_from_c_array(sizeof(')
g.write('array_slice(new_array_from_c_array(_ARR_LEN(')
g.expr(node.left)
g.write('), sizeof(')
g.write('), _ARR_LEN(')
g.expr(node.left)
g.write('), sizeof(')
g.expr(node.left)

View File

@ -191,7 +191,7 @@ void reload_so();
void _vinit();
void _vcleanup();
#define sigaction_size sizeof(sigaction);
#define _ARR_LEN(a) ( (sizeof(a)) / (sizeof((a)[0])) );
#define _ARR_LEN(a) ( (sizeof(a)) / (sizeof(a[0])) )
// ============== wyhash ==============
// Author: Wang Yi