No, the original program writes through iq, which is well defined. Only the optimized program writes through p+1.
87 karma · joined December 14, 2020
guard {
for (int i = 0; i < n; i++) {
defer foo(i);
}
}
Now the compiler has to:1. implement some side of capture/closure mechanism to keep all the 'i's to the end of the guard block
2. do dynamic allocation to store the closures so they can be executed at the end did the scope
1 seems like too much work for such a feature, and 2 is a massive no. Implicit dynamic allocation, in C?
And all of this for nothing. The guard syntax doesn't give any reasonable benefits. They should have just kept it simple; defer happens at the end of the scope, and it just takes 'i' by "reference". It's a shame because it's a feature I would really like to have.