[C/C++] make constant to be l-value.

When compare values, try to put constant or returned value from function call into left side – make it as l-value.
This habit can prevent you from mistake – using ‘=’ instead of ‘==’.
(Compiler can detect this error(mistake)!)

#define X_VAL (100)
...
if( a == X_VAL ) { ... } // This is not good!
if( X_VAL == a) { ... } // Better
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s