Closed rpcarver closed 12 years ago
Your second code snippet is actually wrong, it should be:
if (result == NO)
; // do nothing.
[[db executeQuery:@"VACUUM"] close];
Note the single ; in front of the comment, this is because the semicolon is not part of the macro and will terminate the expression.
See this small example to test this:
#include <stdio.h>
#if 0
#define MY_MACRO printf("Hello, ")
#else
#define MY_MACRO
#endif
int main()
{
if (0)
MY_MACRO;
printf("World!\n");
}
This small programm will always print "World!", no matter if the macro is empty or not.
I'm not the god of macro programmers (I have a record saying otherwise), so if you find other examples of where a macro might be wrong then don't hesitate to open an issue here, and thanks for your effors!
I have found a few examples of unbracketed if statements that will cause bugs when built for release. The following is one example. It can be found in RMDatabaseCache.m in the function - (UIImage )cachedImage:(RMTile)tile withCacheKey:(NSString )aCacheKey
In release mode (with the current pch) this will become
Please do this old programmer's heart a favor and make it part of your coding standards to bracket ALL your if statements. If it only removes one potential bug down the line its worth it. I swear! :)
BTW - you guys are doing a great job!
-- Randy