Skip to main content
Code Review

Return to Revisions

4 of 4
Commonmark migration

I prefer the second one because it can be used with normal compound stamens without modifications or accidentally being used incorrectly.

if (condition)
 I2c_START; 

Type 1: FAIL
Type 2: OK

Of course with good coding standards that can be avoided (always use '{' '}' on if). But every now and then people can be lazy (or just careless) and the second version prevents accidents from happening.

The best solution is not to use macros. Use functions and let the compiler work out when to inline.

Edited:

For billy: (Type 3) no do while

#define I2C_START() \
{ \
 I2C_WAIT_IDLE(); \
 SSP1CON2bits.SEN = 1; \
}

Unfortunately this fails if you use the else part of the if statement:
The trailing semi-colon (on type 3) marks the end of the if statement thus else is not syntactically allowed. At least this gives you a compilation error unlike above. But Type 2 still works as expected.

if (condition)
 I2C_START();
else
 std::cout << "FAIL this test\n";

Type 1: FAIL
Type 2: OK
Type 3: FAIL

Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
default

AltStyle によって変換されたページ (->オリジナル) /