Search code examples
javac++ccommentsjava-3d

Can comments make any difference during the run-time?


Reading What is the best comment I've encouter this comment, upvoted 201 times:

A long time ago, I accidentally fixed a segfault in Java3D by adding a comment. It was 100% reproducible; if I removed the comment, it crashed. As long as the comment was there, it worked fine. I assume it was some bizarre timing issue, but I never did figure out exactly what was happening.

Is this possible?

If he was fixing a segfault in Java3D, I'm guessing he was writing code in Java or C/C++. I thought that in any of these languages, comments are simply erased before the compilation...


Solution

  • I thought that in any of these languages, comments are simply erased before the compilation...

    It might seem so but, unfortunately, this harmless-looking Hello World program wouldn't even compile.

    Why? Because of a comment. The culprit is the path the source. Specifically, \users. The backslash \ is followed by the letter u, denotes the start of a Unicode escape. The trailing sers makes it a ill-formed Unicode escape. (It would have been ok if \u was followed by 4 hex digits -- yes, you need that even in a comment.)

    As such, the code wouldn't even compile due to the comment.

    public class HelloWorld {
    
        /**
         * Source: C:\users\devnull\HelloWorld.java
         */
        public static void main(String[] args) {
            System.out.println("Hello World!");
        }
    }