What is the best way to write comments in C?

In C, we can make comments in two ways:

1>

/* this is one way */

2>

// this is 2nd way

What is the difference between the two? Better than the other?

or

both have the same effect and no difference when compiling or processing on any platform?

Edit: Especially writing code for inline

+5
source share
8 answers

(, ) // , C90. , , , C //, C99, C99.

, C90, (, , ) //, C90.

, , C, C90, , // . ( ) C99, C99 - C99, .

, , .

, gcc // , long long ( C99); // gcc long long.

, , , //. , , C99, .

+4

, , . C, 1980- , , , , , .

+8

, . , , //. , , , /* ... */. , .

.

+5

grep-, , , (STRG + Shift + 7 Eclipse). grepped, , - WITH//. - .

1 #define MY_COUNTER 42
2 if( MY_COUNTER == index )
3 {
4     tempVar = calcSomething();
5     doThis();
6 //    tempVar = MY_COUNTER;
7     doThat();
8 }

grep:
1 #define MY_COUNTER 42
2, (MY_COUNTER == index)
6//tempVar = MY_COUNTER,

grep ( MY_COUNTER), 8 .

1 #define MY_COUNTER 42
2 if( MY_COUNTER == index )
3 {
4     tempVar = calcSomething();
5     doThis();
6 /*    
7     tempVar = MY_COUNTER;
8 */
9     doThat();
8 }

:
1 #define MY_COUNTER 42
2, (MY_COUNTER == index)
7 tempVar = MY_COUNTER,

+3

// , , . /* */.

:

/*

/*printf("foo");*/
printf("bar");

*/

:

/*

//printf("foo");
printf("bar");

*/
+1

: .

0
  • , .

- , , , , .

0
/* this is one way */

//

.

, .

//

.

0

All Articles