4 ms·
QNX is the only compiler I've ever used that removing a comment broke my code at runtime. If I remember right, the comment was: // printf("debug 2"); I added
by fwip 5y ago
QNX is the only compiler I've ever used that removing a comment broke my code at runtime.
If I remember right, the comment was:
// printf("debug 2");
I added in an additional comment directly above that one.
// load-bearing comment, do not remove
- bradrn 5y ago…how‽ What is the explanation for this?
- mst 5y agoNo idea, but I do know there was a gcc port to NCR UNIX bootstrapping off their own compiler that stalled for a while until one of the developers worked out that it unrolled switch statements to if+goto ... and used the label 'dflt:' for the default case of the switch. Sucked to be you if you decided to name one of your own labels that.
- fwip 5y agoHonestly, I'm not sure. In hindsight, I think that there must have been a race condition somewhere else in my code (school project) that this was somehow exposing. Removing the comment reliably resulted in an executable that always did the wrong behavior, and leaving the comment in, the program always worked.
- zoomablemind 5y agoprintf() is an old-school fuzzer, so to speak. It may be just a line, but underneath, the call to it brings in a ton of branching and memory alloc and access. So quite often any latent memory leaks or code issues could lead to such odd behavior. Sometimes it's the opposite - "works" with printf(), but segfaults in some odd place or infiniloops without it. At times like this, -Wall, valgrind, and critical thinking are the ways to "cherchez le 'bug'"... Multithreaded it is? Good luck!
- Arnavion 5y agoThe line in question is a comment, not a call to printf.
- dotancohen 5y agoYou don't know what the compiler is doing behind the scenes before it figures out that is a comment. For instance, it might parse the entire function body for printf() and if it finds it then loads some library, only then getting around to actually parsing the function line by line. Think of Javascript hoisting - only dumber.
- Jenda_ 5y agoThere was a case, which I cannot find now, where the compiler decided whether the function is small enough to inline based on its source code size, including comments. Edit: found it https://medium.com/@c2c/nodejs-a-quick-optimization-advice-7353b820c92e https://medium.com/@c2c/nodejs-a-quick-optimization-advice-7... https://news.ycombinator.com/item?id=18170499 https://news.ycombinator.com/item?id=18170499 Edit 2: the medium.com URL redirects to a non-existent domain when I'm not signed into a Medium account (wtf). http://web.archive.org/web/20151222072514/https://top.fse.guru/nodejs-a-quick-optimization-advice-7353b820c92e?gi=1e133d2b2783 http://web.archive.org/web/20151222072514/https://top.fse.gu...
- Arnavion 5y agoThat may well be the case, but it is not what the comment I replied to was talking about.
- dotancohen 5y ago> // load-bearing comment, do not remove I've actually seen a "load bearing comment" with reflection in a PHP app that I had inherited. And some Python packages uses them for defining tests. But I love the term "load bearing comment". I'm definitely adding this to my vocabulary.
- bostik 5y agoFortran compiler (f77 maybe?) on a Sun system had reserved filenames. In Finland, back in the late 90's first-year chemistry students were still exposed to Fortran as their entry to programming. I was helping another student debug their programming assignment, which blew up the compiler. Over the shoulder I couldn't figure out what it supposedly wrong, so we copied it (via /scratch) to my home directory. I just shortened the name a bit. Tried to compile on my account, it worked. No errors. Confirmed it was the same compiler being invoked. So we copied the file to a new name on the other student's account and tried. Worked. Same file content, two different file names. One compiles fine, another hits internal compiler error paths. Introduction to programming indeed.