On Sun, Oct 16, 2022 at 08:41:32AM -0400, Elad Lahav wrote: > > > > Also, longer term, would you be willing to add code that makes a > > > > simple but dangerous change in order to better illustrate the problem? > I sent a patch, but I'm actually not too thrilled with it. > > The original code was using nd->children[i], which I believe forces a > compliant compiler to re-read nd->children, avoiding the problem. I was > unable to get GCC 8.3 to cache nd->children, even when making the iterator > and the callback take a pointer to a const node. With the new version, which > uses an explicit iterator, the compiler does store nd->children in a > register that is not reloaded across the loop. > > The example I propose can thus fall under the category of "don't do that". > On the other hand, this is just supposed to be a small, self-contained > illustration of the danger. > > What do you think? I took it as is. Many people would not believe that the pointer is all that different than the array access. Thank you! Thanx, Paul