You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For loops are currently transpiled to while loops. I don't know if this is necessary in some cases, however, in the cases I've dealt with, the for loop could be converted directly, which makes the output considerably cleaner.
Example (simplified from the source):
for (loop=0; loop<16; loop++)
if (digit==hexstr[loop]) {
break;
}
}
Based on my understanding, C2Rust is trying to generalize a for loop where there can be a wraparound, however, there is a constant upper bound here, so there's no need for specific handling.
The simpler version is:
for loop_0 in0..16{if digit == hexstr[loop_0 asusize]{break;}}
The text was updated successfully, but these errors were encountered:
You're right that because the loop here has a constant bound, it can be simplified, but obviously that's not true in the general case. I'm not sure how difficult it is in the transpiler to detect such a thing, though. However, I do think the very common C pattern of
for (Ti=start; i<end; i++) {
....
}
for integer types T where start and end are also of type T should be able to be converted to
for i in start..end {
...}
because the upper bound (whether constant or not) ensures there will be no overflow. We'd just need to check that start and end are the same type, as otherwise casts and promotions could allow an overflow.
For loops are currently transpiled to while loops. I don't know if this is necessary in some cases, however, in the cases I've dealt with, the
for
loop could be converted directly, which makes the output considerably cleaner.Example (simplified from the source):
Transpiled to:
Based on my understanding, C2Rust is trying to generalize a for loop where there can be a wraparound, however, there is a constant upper bound here, so there's no need for specific handling.
The simpler version is:
The text was updated successfully, but these errors were encountered: