comments?

i have been wondering this for a while now, so here goes.
does comments/epmty lines etc. affect how fast a program is running, or cause lagg? or could you write all the harry potter books in comments unnafected? (just theorietical ofc, im not actually planning to write the hp books there :P)
It might cause a slightly longer delay to load the source file from the disk when it is compiled, but it is not transfered in the final executable so it has no impact on program performance
Not at all.

As the above post says, it might cause a longer compile time, depending on the number of comments. Usually, one of the first things a compiler will do is bin all of the whitespace and comments from your code.
okay good to know, thanks guys :)
closed account (zb0S216C)
I've noticed that compilers offer a "strip comments" compilation option. Whether comments are actually stripped from the program with or without the option depends on the compiler. As for performance, the compiler will ignore any line that begins with a comment token (// or /*). Therefore, processing time is not wasted on comments since comments do not belong in an executable.

Wazzak
The comments are ripped out by the preprocessor.

Here is a test file:

1
2
3
4
5
6
7
int main()
{
  
  // destroy all comments!
  return 0;
  
}


Here is what the compiler gets from the preprocessor on my system ( g++ -E commtest.cpp)

1
2
3
4
5
6
7
8
9
10
11
12
13
# 1 "commtest.cpp"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "commtest.cpp"


int main()
{


  return 0;

}


The -strip option for the compiler rips out the symbol table and debugging information.


Last edited on
Topic archived. No new replies allowed.