#Looking to receive code review of a ported C function/method

1 messages · Page 1 of 1 (latest)

past nova
past nova
#

So, this obviously should be changed to start[counter]:

        start[i] = total;
        println!("dbg|start = {}", start[counter]);
        total += weight[counter] * count[counter];
    }```
proper vine
# past nova I'm porting a GPL tool written in C to Rust. The Rust compiler I'm using is `1.8...

My C is barely passable, but I think you have issues here

for (i = start[k]; i < l; i++)
    table[i] = j;
i = start[k] as usize;

for inner_counter in i..l as usize {
    s_table.pt_table[inner_counter] = outer_counter as u16;
}```
I think the C code mutates the value of `i` during iteration, but the Rust code doesn't, so they end up different after iteration. I'm not sure if it will have an effect, but it is different.
vagrant shard
#

table[start[k]..l.min(4096)].fill(j);

past nova
past nova
#

The issue is that in the C code, total will be 0 so this scope is not entered:

        fprintf(stderr, "Error: make_table(): Bad table (case b)\n");
        return -1;
    }```
`count[]` and `weight[]` are filled as such:
```    for (i = 1; i <= 16; i++) {
        count[i] = 0;
        printf("bleh %d\n", count[i]);
        weight[i] = 1 << (16 - i);
    }```

Yet in the C tool, `total` is mutated: `total += weight[i] * count[i];`
#

why does Rust allow multiplication with 0 (because as I understand that is the value of count[0]?

tranquil fractal
#

Rust allows multiplication by 0 just like mathematics does. Are you confusing it with division by zero?

past nova