Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (p = 0)
- if (p == 0)
- if (0 == p)
- // bad example - what the writer wrote
- if( i < 0 )
- printf( "%dn", i );
- ++i; // this error is _very_ easy to overlook!
- // good example - what the writer meant
- if( i < 0 ) {
- printf( "%dn", i );
- ++i;
- }
- float x = (y > 3) ? 1.0f : -1.0f;
- float x = foo(2 * ((y > 3) ? a : b) - 1);
- if (5 == variable)
- struct MyStruct // BAD
- {
- int i ; bool j ; char * k ;
- }
- struct MyStruct // GOOD
- {
- MyStruct() : i(0), j(true), k(NULL) : {}
- int i ; bool j ; char * k ;
- }
- MyStruct oMyStruct = { 25, true, "Hello" } ; // BAD
- MyStruct oMyStruct(25, true, "Hello") ; // GOOD
- void doSomething()
- {
- MyStruct s = { 25, true, "Hello" } ;
- // Etc.
- }
- void doSomethingElse()
- {
- MyStruct s = { 25, true, "Hello" } ;
- // Etc.
- }
- // Etc.
- if (bla) {
- for (int i = 0; i < n; ++i)
- foo();
- }
- if (bla) {
- for (int i = 0; i < n; ++i)
- foo();
- }
- if (bla) {
- for (int i = 0; i < n; ++i)
- foo();
- }
- // char * d, * s ;
- strcpy(d, s) ; // BAD
- // std::string d, s ;
- d = s ; // GOOD
- int * i = (int *) malloc(25) ; // Now, I BELIEVE I have an array of 25 ints!
- int * j = new int[25] ; // Now, I KNOW I have an array of 25 ints!
Add Comment
Please, Sign In to add comment