<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 12 Dec 2019 at 04:03, Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <div dir="ltr"><div dir="ltr"><div>Hi Pablo,</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Dec 11, 2019 at 11:33 AM <a href="mailto:tesonep@gmail.com" target="_blank">tesonep@gmail.com</a> <<a href="mailto:tesonep@gmail.com" target="_blank">tesonep@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Nicolas,<br>
  thanks for the comment, you are right the problem is the bad<br>
original code. But my opinion is that it just is not reporting the<br>
situation correctly, generating a warning or non-optimizing the code<br>
looks more like a expected behavior. Because as I have said, using a<br>
constant as index in the last statement generates a meaningful warning<br>
and the non-optimizated version of the function.<br>
<br>
And again as you said, the only thing to learn about all this is that<br>
we should not write crappy code.<br></blockquote><div><br></div><div>Hang on.  "crappy code" is too strong.  Back in tre ANSI days it was not undefined behavior, and in fact I think this only because undefined behavior because C compilers were faced with lots of code where variables were typed int but were being used on 64-bit machines.  Had the C world used long as its default type then there would have been no need to make casting the address of a long into the address of an int undefined behavior.  So this isn't crappy code (if you think of what it means in memory on a 64-bit little endnan machine it is perfectly sensible).  It /is/ code that is inappropriate given C99.</div><div><br></div><div>So yes, we have to bow to the C gods and generate C99 compliant code, but what we were doing here wasn't crappy, it was merely code that became undefined behavior so that C compilers could generate more efficient code for 64-bit systems in the presence of code that contains lots of integer variables declared as int.  So let's just say that we have to generate C99 compliant code.  You'll notice that the Smalltalk code in the original does exactly what you suggest Pablo.</div></div></div></div></blockquote><div><br></div><div>So maybe interesting to see what happens if C89 is specified...</div><div><a href="https://renenyffenegger.ch/notes/development/languages/C-C-plus-plus/GCC/options/std">https://renenyffenegger.ch/notes/development/languages/C-C-plus-plus/GCC/options/std</a> </div><div><br></div><div>Possibly useful sanitizer...</div><div><a href="https://developers.redhat.com/blog/2014/10/16/gcc-undefined-behavior-sanitizer-ubsa">https://developers.redhat.com/blog/2014/10/16/gcc-undefined-behavior-sanitizer-ubsa</a> </div><div><br></div><div>cheers -ben <br></div></div></div>