Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to comment a few lines, with comments inside

Tags:

c++

c

comments

I have a program like this

int main(){ 

    char c;
    int i; /* counter */
    double d;

    return 0;
}

if I want to comment out char, int and double, and just have return uncommented, can I do it? the comment that's already there stops the comment.. Is there an easy/fast way to comment that out?

like image 570
pvinis Avatar asked Oct 15 '10 09:10

pvinis


4 Answers

int main(){ 
#if 0
    char c;
    int i; /* counter */
    double d;
#endif
    return 0;
}

Not strictly a comment, but the effect is what you want and it's easy to revert.

This also scales well to larger code blocks, especially if you have an editor that can match the start and end of the #if..#endif.

like image 157
Steve Townsend Avatar answered Dec 23 '22 00:12

Steve Townsend


int main(){ 

/*
    char c;
    int i; // counter
    double d;
*/
    return 0;
}
like image 41
mlusiak Avatar answered Dec 23 '22 01:12

mlusiak


If your compiler supports the // notation for comments (non-standard in C, but quite commonly supported), use an editor that can toggle a whole block of lines with these.

like image 37
Bruno Avatar answered Dec 22 '22 23:12

Bruno


In C99

int main(){ 

//    char c;
//    int i; /* counter */
//    double d;

    return 0;
}
like image 22
JeremyP Avatar answered Dec 23 '22 01:12

JeremyP