Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> To fix that, the Itanium has the option to do a speculative load, which may or may not succeed at a later point. So you can do a load from a dubious pointer, then check if the pointer is fine (e.g. is it in bounds? Is it a null pointer?), and only once it has been validated you make use of the result.

Way back in the day, as a fairly young engineer, I was assigned to a project to get a bunch of legacy code migrated from Alpha to Itanium. The assignment was to "make it compile, run, and pass the tests. Do nothing else. At all."

We were using the Intel C compiler on OpenVMS and every once in a while would encounter a crash in a block of code that looked something like this:

   if(ptr != NULL && ptr->val > 0) {
     //do something
   } else {
     //init the ptr
   }
It was evaluating both parts of the if statement simultaneously and crashing on the second. Not being allowed to spend too much time debugging or investigating the compiler options, we did the following:

   if(ptr != NULL) {
     if(ptr->val > 0) {
       //do something
     }
   } else {
     //init the ptr
   }
Which resolved the problem!

EDIT - I recognize that the above change introduces a potential bug in the program ;) Obviously I wasn't copying code verbatim - it was 10-15 years ago! But you get the picture - the compiler was wonky, even the one you paid money for.



When I was learning C many years ago I was warned that some compilers don't support boolean short circuiting and thus you had to be careful with it.


Is this one of those rare cases where using a goto would be reasonable?


The main case I ever found was implement missing language features. E.G.

break 3; // Break 3 levels up

break LABEL; // Break to a named label - safer-ish than goto

goto LABEL; // When you have no other option.

Usually for breaking out of a really deep set of loops to an outer loop. Such as a data stream reset, end of data, or for an error so bad a different language might E.G. throw an error and usually die.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: