#define continue break
There's my choice. It's one of the few that will actually compile and the runtime effect is not super immediately detectable. #define breakFor example, we could force a double-valued transcendental function to float and back for a small loss of precision in normal cases:
#define sin(d) ((double)sinf(d))
Which yields... double i = 10
--> i = 10.0000000000
sin(i) = -0.5440211109
sinf(i) = -0.5440211296
delta = 0.0000000187
double i = 0.25
--> i = 0.2500000000
sin(i) = 0.2474039593
sinf(i) = 0.2474039644
delta = -0.0000000051
double i = 9999999.999999
--> i = 9999999.9999989998
sin(i) = 0.4205487007
sinf(i) = 0.4205478132
delta = 0.0000008875
(Format string was %25.10f, fwiw.)Another idea: Let's say we know the application relies on rand() to produce the correct distribution for testing, or maybe to generate session keys. Changing the semantics of the RNG won't result in a compiler bug, but it might result in the tests failing to cover all cases, or a horrible security breach.
The rest would probably be found quite quickly, but omitting volatiles could lead to hard to detect bugs that will only manifest themselves under specific circumstances.
The only legitimate reasons for using volatile generally involve memory-mapped IO and POSIX signal handlers. C's volatile is nothing like Java's volatile and has very weak semantics. With lock-based code you generally have nothing to worry about because lock/unlock has load-acquire/store-release semantics. But if you're writing lock-free code, volatile is useless in general and you need to think carefully about how atomicity is affected by memory alignment and operand size (e.g. a byte write that might look atomic implicitly turns into a non-atomic read-modify-write), explicit memory barriers, etc.
So defining away volatile won't actually impact most applications unless they're relying on very compiler-specific behavior.
The values of automatic variables are unspecified after a call to longjmp() if they meet all the following criteria:
· they are local to the function that made the corresponding setjmp(3) call;
· their values are changed between the calls to setjmp(3) and longjmp(); and
· they are not declared as volatile.
I've had bugs that made me go half-crazy before someone reminded me that you have to use volatile in these situations.I'd personally go with while -> if, that's very sneaky.
int main(void)
{
while (1) break;
return 0;
}#define pthread_mutex_lock(x)
#define pthread_mutex_unlock(x)
#define goto
would have? It doesn't looks valid, because if I have myLabel:
/* some code*/
goto myLabel;
would produce myLabel;
Which, as far as I know shouldn't compile because it expects either a normal expression or a definition/declaration and myLabel; doesn't appears to be any of them. (Maybe I'm missing something) #define free(x)
Most tests still pass, but once the program's been running for a while you'll get a nice memory leak. Fails if your mortal enemy runs leak checks as part of their standard test suite or other QA, or has a high enough allocation rate to quickly turn up such issues.Problem of course is to find a nice size range for the program at hand.
#define if(x) if(rand()<0.0001 && (x))
#define malloc(x) malloc(random())
#define free(x) do { free(x); x = NULL; } while (0)
Assuming you can turn it off just before shipping, this will hide many forms of double free during development which then show up when the evil line is deleted.There's also people doing stupid shit like free(&x), but those people don't need evil macros to dick up their code. :)
#define printf(...) printf(__VA_ARGS__); puts("\n\n\n\nFAIL!") __attribute__((constructor)) void __maiin(void)
{
if (rand() < 0.05) exit();
//if (rand() < 0.05) close(1);
//if (rand() < 0.05) main(); // and so on ..
}
The program will randomly quit before main() is executed.I did this one to a friend (briefly) during school.
#define assert(x) ((void)(x))
Most of these would cause an immediate flood of hints and / or warnings; but an assert that did nothing but evaluate its argument could lurk for some days, especially if the developers in question don't spelunk with a debugger very often.* asserts are used in a defensive programming style to state invariants
* the enemy developers will be reasoning about the code assuming that asserts which didn't fire were true
* when debugging, they'll read the code and prematurely dismiss valid theories as to why the bug exists based on what they read in the assertions
If the problem was to slow down early development I'd absolutely agree with you.
#define rand() (rand() % 100) #define memmove memcpy
#define default default: break; case 0xfeceface#define do
You could even slip that into a makefile (-Ddo=) and it might not be noticed.