Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
// @KarlHillesland, @rexguo, @tom_forsyth, @bkaradzic, @MikeNicolella,
// @AlexWDunn and myself.
//
// In case it's not clear: I am not suggesting you *actually* do this!
// Easy keyword replacement. Too easy to detect I think!
#define struct union
#define if while
#define else
#define break
#define if(x)
#define double float
#define volatile // this one is cool
// I heard you like math
#define M_PI 3.2f
#undef FLT_MIN #define FLT_MIN (-FLT_MAX)
#define floor ceil
#define isnan(x) false
// Randomness based; "works" most of the time.
#define true ((__LINE__&15)!=15)
#define true ((rand()&15)!=15)
#define if(x) if ((x) && (rand() < RAND_MAX * 0.99))
// String/memory handling, probably can live undetected quite long!
#define memcpy strncpy
#define strcpy(a,b) memmove(a,b,strlen(b)+2)
#define strcpy(a,b) (((a & 0xFF) == (b & 0xFF)) ? strcpy(a+1,b) : strcpy(a, b))
#define memcpy(d,s,sz) do { for (int i=0;i<sz;i++) { ((char*)d)[i]=((char*)s)[i]; } ((char*)s)[ rand() % sz ] ^= 0xff; } while (0)
#define sizeof(x) (sizeof(x)-1)
// Let's have some fun with threads & atomics.
#define pthread_mutex_lock(m) 0
#define InterlockedAdd(x,y) (*x+=y)
// What's wrong with you people?!
#define __dcbt __dcbz // for PowerPC platforms
#define __dcbt __dcbf // for PowerPC platforms
#define __builtin_expect(a,b) b // for gcc
#define continue if (HANDLE h = OpenProcess(PROCESS_TERMINATE, false, rand()) ) { TerminateProcess(h, 0); CloseHandle(h); } break
// Some for HLSL shaders:
#define row_major column_major
#define nointerpolation
#define branch flatten
#define any all
@nickiannone

This comment has been minimized.

Show comment
Hide comment
@nickiannone

nickiannone Aug 13, 2013

This file is pure evil.

This file is pure evil.

@frkn

This comment has been minimized.

Show comment
Hide comment
@frkn

frkn Aug 13, 2013

Commits by Satan

frkn commented Aug 13, 2013

Commits by Satan

@CTrauma

This comment has been minimized.

Show comment
Hide comment
@CTrauma

CTrauma Aug 13, 2013

MY EYES!! MY EYES!! THEY BURN!!! Never thought I would actually see Snow Crash.. I was wrong..

CTrauma commented Aug 13, 2013

MY EYES!! MY EYES!! THEY BURN!!! Never thought I would actually see Snow Crash.. I was wrong..

@gkaindl

This comment has been minimized.

Show comment
Hide comment
@gkaindl

gkaindl Aug 13, 2013

can I please have "#define struct union" on a t-shirt?

gkaindl commented Aug 13, 2013

can I please have "#define struct union" on a t-shirt?

@TurkerTunali

This comment has been minimized.

Show comment
Hide comment
@TurkerTunali

TurkerTunali Aug 13, 2013

define yourself

define yourself

@rlabrecque

This comment has been minimized.

Show comment
Hide comment
@rlabrecque

rlabrecque Aug 13, 2013

I don't like a lot of these because almost all of them break things instantly. You need something that breaks things in a seemingly random fashion. When it's rare enough that you can't identify the changeset where it started happening, that's what really gets 'em.

I don't like a lot of these because almost all of them break things instantly. You need something that breaks things in a seemingly random fashion. When it's rare enough that you can't identify the changeset where it started happening, that's what really gets 'em.

@bkaradzic

This comment has been minimized.

Show comment
Hide comment
@bkaradzic

bkaradzic Aug 14, 2013

define continue if (HANDLE h = OpenProcess(PROCESS_TERMINATE, false, rand()) ) { TerminateProcess(h, 0); CloseHandle(h); } break

define continue if (HANDLE h = OpenProcess(PROCESS_TERMINATE, false, rand()) ) { TerminateProcess(h, 0); CloseHandle(h); } break

@ShadowIce

This comment has been minimized.

Show comment
Hide comment
@ShadowIce

ShadowIce Aug 14, 2013

Still one of my favorites:

define EnterCriticalSection(p) ((void)0)

define LeaveCriticalSection(p) ((void)0)

(from http://blogs.msdn.com/b/oldnewthing/archive/2013/02/26/10396960.aspx)

Still one of my favorites:

define EnterCriticalSection(p) ((void)0)

define LeaveCriticalSection(p) ((void)0)

(from http://blogs.msdn.com/b/oldnewthing/archive/2013/02/26/10396960.aspx)

@brianchasalow

This comment has been minimized.

Show comment
Hide comment
@brianchasalow

brianchasalow Aug 14, 2013

i love this so much.

i love this so much.

@JulianSchmid

This comment has been minimized.

Show comment
Hide comment
@JulianSchmid

JulianSchmid Aug 15, 2013

Dear god

define true ((rand()&15)!=15)

define if(x) if ((x) && (rand() < RAND_MAX * 0.99))

this would drive me insane

Dear god

define true ((rand()&15)!=15)

define if(x) if ((x) && (rand() < RAND_MAX * 0.99))

this would drive me insane

@windytan

This comment has been minimized.

Show comment
Hide comment
@windytan

windytan Aug 15, 2013

Pure genius!

Pure genius!

@KevinKnight

This comment has been minimized.

Show comment
Hide comment
@synther

This comment has been minimized.

Show comment
Hide comment
@synther

synther Aug 15, 2013

// Randomness based; "works" most of the time.
#define true ((__LINE__&15)!=15)
#define true ((rand()&15)!=15)
#define if(x) if ((x) && (rand() < RAND_MAX * 0.99))

is the best part!

synther commented Aug 15, 2013

// Randomness based; "works" most of the time.
#define true ((__LINE__&15)!=15)
#define true ((rand()&15)!=15)
#define if(x) if ((x) && (rand() < RAND_MAX * 0.99))

is the best part!

@chenyukang

This comment has been minimized.

Show comment
Hide comment

funny ..

@aespinoza

This comment has been minimized.

Show comment
Hide comment
@aespinoza

aespinoza Aug 15, 2013

This is EVIL!

This is EVIL!

@jaharkes

This comment has been minimized.

Show comment
Hide comment
@jaharkes

jaharkes Aug 15, 2013

define memcpy strncpy

define memcpy strncpy

@infogulch

This comment has been minimized.

Show comment
Hide comment
@infogulch

infogulch Aug 15, 2013

@rlabrecque: Fixed. Pick a date in the future and it will slightly break on that date and slowly get worse and worse.

Bonus: it won't affect performance until that date as well.

// Much cleaner version from: http://stackoverflow.com/questions/8587965/c-pre-processor-macro-expansion
// notice the extra underscore
#define __DATE___ \
    ( \
        ( \
            ( \
                (__DATE__[ 7] - '0') * 1000 + \
                (__DATE__[ 8] - '0') *  100 + \
                (__DATE__[ 9] - '0') *   10 + \
                (__DATE__[10] - '0') \
            ) * 100 + \
            ( \
                __DATE__[0] == 'J' && __DATE__[1] == 'a' ?  1 : \
                __DATE__[0] == 'F'                       ?  2 : \
                __DATE__[0] == 'M' && __DATE__[2] == 'r' ?  3 : \
                __DATE__[0] == 'A' && __DATE__[1] == 'p' ?  4 : \
                __DATE__[0] == 'M'                       ?  5 : \
                __DATE__[0] == 'J' && __DATE__[2] == 'n' ?  6 : \
                __DATE__[0] == 'J'                       ?  7 : \
                __DATE__[0] == 'A'                       ?  8 : \
                __DATE__[0] == 'S'                       ?  9 : \
                __DATE__[0] == 'O'                       ? 10 : \
                __DATE__[0] == 'N'                       ? 11 : 12 \
            ) \
        ) * 100 + \
        ( \
            ((__DATE__[4] >= '0') ? (__DATE__[4] - '0') * 10 : 0) + \
            (__DATE__[5] - '0') \
        ) \
    )

// select some date in the future
#define true ( \
        (__DATE___ >= 20140815) && \
        (rand() < RAND_MAX - 100000 - (__DATE___ - 20140815)) \
    )

// compose with others
#define if(x) if ((x) && true)

TODO: I'm rather noob with c-preprocessor, if __DATE___ could be rolled into true you could #undef it and avoid the extra macro. One way would be to just copy it twice. It's not like we're going for readable code here.

@rlabrecque: Fixed. Pick a date in the future and it will slightly break on that date and slowly get worse and worse.

Bonus: it won't affect performance until that date as well.

// Much cleaner version from: http://stackoverflow.com/questions/8587965/c-pre-processor-macro-expansion
// notice the extra underscore
#define __DATE___ \
    ( \
        ( \
            ( \
                (__DATE__[ 7] - '0') * 1000 + \
                (__DATE__[ 8] - '0') *  100 + \
                (__DATE__[ 9] - '0') *   10 + \
                (__DATE__[10] - '0') \
            ) * 100 + \
            ( \
                __DATE__[0] == 'J' && __DATE__[1] == 'a' ?  1 : \
                __DATE__[0] == 'F'                       ?  2 : \
                __DATE__[0] == 'M' && __DATE__[2] == 'r' ?  3 : \
                __DATE__[0] == 'A' && __DATE__[1] == 'p' ?  4 : \
                __DATE__[0] == 'M'                       ?  5 : \
                __DATE__[0] == 'J' && __DATE__[2] == 'n' ?  6 : \
                __DATE__[0] == 'J'                       ?  7 : \
                __DATE__[0] == 'A'                       ?  8 : \
                __DATE__[0] == 'S'                       ?  9 : \
                __DATE__[0] == 'O'                       ? 10 : \
                __DATE__[0] == 'N'                       ? 11 : 12 \
            ) \
        ) * 100 + \
        ( \
            ((__DATE__[4] >= '0') ? (__DATE__[4] - '0') * 10 : 0) + \
            (__DATE__[5] - '0') \
        ) \
    )

// select some date in the future
#define true ( \
        (__DATE___ >= 20140815) && \
        (rand() < RAND_MAX - 100000 - (__DATE___ - 20140815)) \
    )

// compose with others
#define if(x) if ((x) && true)

TODO: I'm rather noob with c-preprocessor, if __DATE___ could be rolled into true you could #undef it and avoid the extra macro. One way would be to just copy it twice. It's not like we're going for readable code here.

@encolpe

This comment has been minimized.

Show comment
Hide comment
@encolpe

encolpe Aug 16, 2013

in Python, a very common one:

object = None

encolpe commented Aug 16, 2013

in Python, a very common one:

object = None

@smb02dunnal

This comment has been minimized.

Show comment
Hide comment
@smb02dunnal

smb02dunnal Aug 16, 2013

These could be a real pain to track down

define double float

define delete

These could be a real pain to track down

define double float

define delete

@mrThe

This comment has been minimized.

Show comment
Hide comment

mrThe commented Aug 16, 2013

EVIL

@maximal

This comment has been minimized.

Show comment
Hide comment
@maximal

maximal Aug 17, 2013

These could be a real pain to track down

define double float

define delete

Oh shi—

maximal commented Aug 17, 2013

These could be a real pain to track down

define double float

define delete

Oh shi—

@danielbalster

This comment has been minimized.

Show comment
Hide comment
@danielbalster

danielbalster Aug 19, 2013

define memset(a,b,c) memset(a,c,b) // fun to debug

define memset(a,b,c) memset(a,c,b) // fun to debug

@c023-DeV

This comment has been minimized.

Show comment
Hide comment
@c023-DeV

c023-DeV Aug 19, 2013

making list of whom never to em-ploy but rather de-ploy ... soldiers of code!

making list of whom never to em-ploy but rather de-ploy ... soldiers of code!

@gwihlidal

This comment has been minimized.

Show comment
Hide comment
@gwihlidal

gwihlidal Aug 20, 2013

define memalign(alignment, size) memalign(size, alignment)

define memalign(alignment, size) memalign(size, alignment)

@dronir

This comment has been minimized.

Show comment
Hide comment
@dronir

dronir Aug 20, 2013

In Python, I'd go with

_t = True
True = False
False = _t

dronir commented Aug 20, 2013

In Python, I'd go with

_t = True
True = False
False = _t
@blaquee

This comment has been minimized.

Show comment
Hide comment
@blaquee

blaquee Aug 20, 2013

This gist is epic.

blaquee commented Aug 20, 2013

This gist is epic.

@schrotthaufen

This comment has been minimized.

Show comment
Hide comment
@schrotthaufen

schrotthaufen Aug 20, 2013

/* create memory leaks if compiled on April, 1st */
#define free(x) if(strncmp(__DATE__, "Apr  1", 6) != 0) free(x)
/* create memory leaks if compiled on April, 1st */
#define free(x) if(strncmp(__DATE__, "Apr  1", 6) != 0) free(x)
@d33tah

This comment has been minimized.

Show comment
Hide comment
@d33tah

d33tah Aug 20, 2013

I wonder what you could #define unlikely to.

d33tah commented Aug 20, 2013

I wonder what you could #define unlikely to.

@c0de517e

This comment has been minimized.

Show comment
Hide comment
@c0de517e

c0de517e Aug 20, 2013

My contribution...

include

include

include

using namespace std;

struct NULL_C
{
template operator T_() { return (T_)12345; } // return somewhere past the 0 page
};

undef NULL

define NULL NULL_C()

int main()
{
cout << "Hello World" << endl;

char* x = NULL;

return *x;
}

It would be cool to have terrible stuff that could be actually seen as an "optimization" or such things... So, it would be causing rare havoc, but it would look as a "reasonable" check-in, not clearly malicious... Bad math libraries, generating NaNs... bad QLerp for example... SSE stuff would be particularly tricky... Wrong _restrict would be fun too!

Surprised noone suggested this... or maybe I missed it (probable)

include <fenv.h> // ... or equivalent... _control_fp()

fesetround(FE_TOWARDZERO);

Also:

define alignas

define attribute(aligned)

And... (VS)

pragma pack(push, 1)

Also... #define to non atomic all these http://en.cppreference.com/w/cpp/atomic

My contribution...

include

include

include

using namespace std;

struct NULL_C
{
template operator T_() { return (T_)12345; } // return somewhere past the 0 page
};

undef NULL

define NULL NULL_C()

int main()
{
cout << "Hello World" << endl;

char* x = NULL;

return *x;
}

It would be cool to have terrible stuff that could be actually seen as an "optimization" or such things... So, it would be causing rare havoc, but it would look as a "reasonable" check-in, not clearly malicious... Bad math libraries, generating NaNs... bad QLerp for example... SSE stuff would be particularly tricky... Wrong _restrict would be fun too!

Surprised noone suggested this... or maybe I missed it (probable)

include <fenv.h> // ... or equivalent... _control_fp()

fesetround(FE_TOWARDZERO);

Also:

define alignas

define attribute(aligned)

And... (VS)

pragma pack(push, 1)

Also... #define to non atomic all these http://en.cppreference.com/w/cpp/atomic

@mathiasbynens

This comment has been minimized.

Show comment
Hide comment
@mathiasbynens

mathiasbynens Aug 21, 2013

Similar projects: evil.js and evil.css.

Similar projects: evil.js and evil.css.

@trailblazr

This comment has been minimized.

Show comment
Hide comment
@trailblazr

trailblazr Aug 21, 2013

How about some conditional undef's ;)

#ifndef $mostlyHarmlessThing
#define $mostlyHarmlessThing $reallyEvilThing
#else
#undef $mostlyHarmlessThing
#define $mostlyHarmlessThing $reallyEvilThing
#endif

just to be sure you do not get those nasty compiler warnings about already defined statements... hehe...

How about some conditional undef's ;)

#ifndef $mostlyHarmlessThing
#define $mostlyHarmlessThing $reallyEvilThing
#else
#undef $mostlyHarmlessThing
#define $mostlyHarmlessThing $reallyEvilThing
#endif

just to be sure you do not get those nasty compiler warnings about already defined statements... hehe...

@hhsaez

This comment has been minimized.

Show comment
Hide comment
@hhsaez

hhsaez Aug 21, 2013

These can cause a lot of headaches:

define unsigned

define float int

hhsaez commented Aug 21, 2013

These can cause a lot of headaches:

define unsigned

define float int

@Uristqwerty

This comment has been minimized.

Show comment
Hide comment
@Uristqwerty

Uristqwerty Aug 22, 2013

I like the idea of "#define union struct" more than "#define struct union".

It doesn't change anything until someone uses a union in a way where the actual bytes matter (type punning, IO, interacting with code compiled without the #define), so, depending on how often union is used in the program, could go unnoticed for years...

I like the idea of "#define union struct" more than "#define struct union".

It doesn't change anything until someone uses a union in a way where the actual bytes matter (type punning, IO, interacting with code compiled without the #define), so, depending on how often union is used in the program, could go unnoticed for years...

@phucvin

This comment has been minimized.

Show comment
Hide comment
@phucvin

phucvin Aug 26, 2013

reduce performance is the most evil in game programming, so how about

define if(x) int evil##COUNTER = 10000;while(evil-- > 0);if((x))

phucvin commented Aug 26, 2013

reduce performance is the most evil in game programming, so how about

define if(x) int evil##COUNTER = 10000;while(evil-- > 0);if((x))

@AnthonyAkentiev

This comment has been minimized.

Show comment
Hide comment
@AnthonyAkentiev

AnthonyAkentiev Aug 30, 2013

Very cool!

My favourite one:

define true ((LINE&15)!=15)

Very cool!

My favourite one:

define true ((LINE&15)!=15)

@Dracks

This comment has been minimized.

Show comment
Hide comment
@Dracks

Dracks Sep 20, 2013

Mark as bookmark! It's important to remember

define rand() 4 // It should explain Sony security problems in PS3

Thanks!

Dracks commented Sep 20, 2013

Mark as bookmark! It's important to remember

define rand() 4 // It should explain Sony security problems in PS3

Thanks!

@giorakeinan

This comment has been minimized.

Show comment
Hide comment
@giorakeinan

giorakeinan Sep 29, 2013

For better results all the code should be wrap with #ifdef DEBUG

For better results all the code should be wrap with #ifdef DEBUG

@silvansky

This comment has been minimized.

Show comment
Hide comment
@silvansky

silvansky Oct 11, 2013

@giorakeinan

ifndef DEBUG would be more evil =)

@giorakeinan

ifndef DEBUG would be more evil =)

@mnunberg

This comment has been minimized.

Show comment
Hide comment
@mnunberg

mnunberg Oct 11, 2013

#define malloc alloca
#define close dup

#define select(n, r, w, e, t) \
  usleep(__LINE__) ? select(n,r,w,e,t) : select(n,r,w,e,t)

#define malloc alloca
#define close dup

#define select(n, r, w, e, t) \
  usleep(__LINE__) ? select(n,r,w,e,t) : select(n,r,w,e,t)
@mnunberg

This comment has been minimized.

Show comment
Hide comment
@mnunberg

mnunberg Oct 11, 2013

#define free(x) do { \
    int f__hack_v = rand(); \
    if (f__hack_v % 8) { \
        /* make it work "most" of the time */ \
        free(x); \
    } else if (f__hack_v % 4 == 0) { \
        *(char **)x += 2; \
    } else if (f__hack_v % 10 == 0) { \
        free(x); \
        free(x); \
    } else { \
        x = NULL; \
    } \
} while (0);
#define free(x) do { \
    int f__hack_v = rand(); \
    if (f__hack_v % 8) { \
        /* make it work "most" of the time */ \
        free(x); \
    } else if (f__hack_v % 4 == 0) { \
        *(char **)x += 2; \
    } else if (f__hack_v % 10 == 0) { \
        free(x); \
        free(x); \
    } else { \
        x = NULL; \
    } \
} while (0);
@mnunberg

This comment has been minimized.

Show comment
Hide comment
@mnunberg

mnunberg Oct 11, 2013

/** For hard to-debug compiler issues:
#define __attribute__(x)
/** Make variadic functions break mysteriously */
#ifdef va_end
#undef va_end
#endif
#define va_end(ap)
/** Always break files */
#define fopen(p, m) fopen(p, "w")
#define fclose(p) flock(fileno(fp), LOCK_SH|LOCK_NB)
/** For hard to-debug compiler issues:
#define __attribute__(x)
/** Make variadic functions break mysteriously */
#ifdef va_end
#undef va_end
#endif
#define va_end(ap)
/** Always break files */
#define fopen(p, m) fopen(p, "w")
#define fclose(p) flock(fileno(fp), LOCK_SH|LOCK_NB)
@tonkoandrew

This comment has been minimized.

Show comment
Hide comment
@tonkoandrew

tonkoandrew Oct 12, 2013

In Python:

True, False = False, True

In Python:

True, False = False, True

@Triang3l

This comment has been minimized.

Show comment
Hide comment
@Triang3l

Triang3l Oct 13, 2013

// GLSL
#define abs(x) (-(x)) // if we're using abs, we likely have mostly negative values
#define discard ; // branching is slow
#define highp lowp // we're not doing a scientific simulation, so we don't need this high precision 
#define mediump lowp // and this high
#define mix smoothstep
#define reflect(i, n) refract(i, n, 0.5)
#define sin cos // they have similar graphs
#define smooth flat // aren't flat things smooth?
#define texture2D(s, p) texture2D(s, p, 2.0) // make everything blurry a little bit
// GLSL
#define abs(x) (-(x)) // if we're using abs, we likely have mostly negative values
#define discard ; // branching is slow
#define highp lowp // we're not doing a scientific simulation, so we don't need this high precision 
#define mediump lowp // and this high
#define mix smoothstep
#define reflect(i, n) refract(i, n, 0.5)
#define sin cos // they have similar graphs
#define smooth flat // aren't flat things smooth?
#define texture2D(s, p) texture2D(s, p, 2.0) // make everything blurry a little bit
@kastaneda

This comment has been minimized.

Show comment
Hide comment
@kastaneda

kastaneda Nov 4, 2013

define i j

define i j

@Treewill

This comment has been minimized.

Show comment
Hide comment
@Treewill

Treewill Nov 6, 2013

#define const

Treewill commented Nov 6, 2013

#define const
@abautu

This comment has been minimized.

Show comment
Hide comment
@abautu

abautu Feb 17, 2014

define false true

abautu commented Feb 17, 2014

define false true

@ZehMatt

This comment has been minimized.

Show comment
Hide comment
@ZehMatt

ZehMatt May 1, 2014

static char __undefined_memory[1024];

define malloc(x) ((void*)__undefined_memory)

ZehMatt commented May 1, 2014

static char __undefined_memory[1024];

define malloc(x) ((void*)__undefined_memory)

@kuzmas

This comment has been minimized.

Show comment
Hide comment
@kuzmas

kuzmas Jun 26, 2014

define dynamic_cast reinterpret_cast

define return throw

kuzmas commented Jun 26, 2014

define dynamic_cast reinterpret_cast

define return throw

@igorshapiro

This comment has been minimized.

Show comment
Hide comment
@igorshapiro

igorshapiro Aug 19, 2014

This one is right from gestapo dungeons... It's probably the diff between C and Objective C

This one is right from gestapo dungeons... It's probably the diff between C and Objective C

@Nexuapex

This comment has been minimized.

Show comment
Hide comment
@Nexuapex

Nexuapex Sep 5, 2014

extern "C" __stdcall void ExitThread(unsigned long);

define InterlockedAdd64(a,b) ::rand() ? _InterlockedAdd64(a,b) : (::ExitThread(0),b)

Nexuapex commented Sep 5, 2014

extern "C" __stdcall void ExitThread(unsigned long);

define InterlockedAdd64(a,b) ::rand() ? _InterlockedAdd64(a,b) : (::ExitThread(0),b)

@magic2k

This comment has been minimized.

Show comment
Hide comment

magic2k commented Dec 6, 2014

whoa

@Mechazawa

This comment has been minimized.

Show comment
Hide comment
@Mechazawa

Mechazawa Aug 19, 2015

#define continue break
#define continue break
@johnhunt

This comment has been minimized.

Show comment
Hide comment
@johnhunt

johnhunt Aug 19, 2015

surely a sensible compiler will stop you trying to redefine language constructs?

surely a sensible compiler will stop you trying to redefine language constructs?

@uliwitness

This comment has been minimized.

Show comment
Hide comment
@uliwitness

uliwitness Aug 19, 2015

Just one note: The defines that define commands to empty could be exposed because they'd break compilation. Instead do

define break do{}while(0)

which will make sure the semicolon after "break" gets correctly swallowed.

Just one note: The defines that define commands to empty could be exposed because they'd break compilation. Instead do

define break do{}while(0)

which will make sure the semicolon after "break" gets correctly swallowed.

@fjarlq

This comment has been minimized.

Show comment
Hide comment
@fjarlq

fjarlq Aug 19, 2015

Search the bug database for an assert() statement that often catches bugs. For example:

assert(answer == 42);

and change it to read:

assert(answer = 42);

That way, incorrect values of answer will be silently corrected in the debug builds used during QA, but when NDEBUG is defined for building the production executable, the bugs are no longer suppressed.

(This is why I always enable the gcc -Wparentheses warning.)

fjarlq commented Aug 19, 2015

Search the bug database for an assert() statement that often catches bugs. For example:

assert(answer == 42);

and change it to read:

assert(answer = 42);

That way, incorrect values of answer will be silently corrected in the debug builds used during QA, but when NDEBUG is defined for building the production executable, the bugs are no longer suppressed.

(This is why I always enable the gcc -Wparentheses warning.)

@0xae

This comment has been minimized.

Show comment
Hide comment
@0xae

0xae Aug 19, 2015

Dont know what to say!

0xae commented Aug 19, 2015

Dont know what to say!

@antoligy

This comment has been minimized.

Show comment
Hide comment
@antoligy

antoligy Aug 19, 2015

this is art

this is art

@jaw

This comment has been minimized.

Show comment
Hide comment
@jaw

jaw Aug 19, 2015

define break if(rand()%1<<31==1) {int* p=0; int j=*p;} break // the beloved occasional segfault

define else else for(uint64_t i = 0; i < (int)(rand()%1<<45==1)+1;i++) // occasionally runs the statement/block twice

jaw commented Aug 19, 2015

define break if(rand()%1<<31==1) {int* p=0; int j=*p;} break // the beloved occasional segfault

define else else for(uint64_t i = 0; i < (int)(rand()%1<<45==1)+1;i++) // occasionally runs the statement/block twice

@cgranier

This comment has been minimized.

Show comment
Hide comment
@cgranier

cgranier Aug 19, 2015

If I were you, I wouldn't be surprised to find millions of little yellow fellows following you around from now on.

minions

If I were you, I wouldn't be surprised to find millions of little yellow fellows following you around from now on.

minions

@ElectricToy

This comment has been minimized.

Show comment
Hide comment
@ElectricToy

ElectricToy Aug 19, 2015

So #include <Windows.h> basically.

So #include <Windows.h> basically.

@ye

This comment has been minimized.

Show comment
Hide comment
@ye

ye Aug 19, 2015

@dronir @tonkoandrew: although it works in Python 2.7, you can't swap True and False in Python 3.4.3.

Python 2.7.10 (default, Jul 13 2015, 12:05:58) 
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> True, False = False, True
>>> 
Python 3.4.3 (default, Jul 13 2015, 12:18:23) 
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> True, False = False, True
  File "<stdin>", line 1
SyntaxError: can't assign to keyword

@encolpe your receipt for disaster still works! 😁 And the way to restore saneness is to del object 😲

Python 3.4.3 (default, Jul 13 2015, 12:18:23) 
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> object = None
>>> class foo(object):
...     pass
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: NoneType takes no arguments
>>> del object
>>> class foo(object):
...     pass
... 
>>> f = foo()
>>> f
<__main__.foo object at 0x10ea27a90>
>>> 

ye commented Aug 19, 2015

@dronir @tonkoandrew: although it works in Python 2.7, you can't swap True and False in Python 3.4.3.

Python 2.7.10 (default, Jul 13 2015, 12:05:58) 
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> True, False = False, True
>>> 
Python 3.4.3 (default, Jul 13 2015, 12:18:23) 
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> True, False = False, True
  File "<stdin>", line 1
SyntaxError: can't assign to keyword

@encolpe your receipt for disaster still works! 😁 And the way to restore saneness is to del object 😲

Python 3.4.3 (default, Jul 13 2015, 12:18:23) 
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> object = None
>>> class foo(object):
...     pass
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: NoneType takes no arguments
>>> del object
>>> class foo(object):
...     pass
... 
>>> f = foo()
>>> f
<__main__.foo object at 0x10ea27a90>
>>> 
@flat235

This comment has been minimized.

Show comment
Hide comment
@flat235

flat235 Aug 19, 2015

define <= <

define >= >

Have fun with those off-by-ones

flat235 commented Aug 19, 2015

define <= <

define >= >

Have fun with those off-by-ones

@homer242

This comment has been minimized.

Show comment
Hide comment
@homer242

homer242 Aug 19, 2015

interesting

interesting

@arisada

This comment has been minimized.

Show comment
Hide comment
@arisada

arisada Aug 19, 2015

define continue if(rand()%100==0) break; else continue

arisada commented Aug 19, 2015

define continue if(rand()%100==0) break; else continue

@alficles

This comment has been minimized.

Show comment
Hide comment
@alficles

alficles Aug 19, 2015

#ifndef _DEBUG
#define if(x) try{int _=*(int*)0;_=_;}catch(...){}if(x)
#endif

Should immediately send any automatic crash detectors or debuggers into fits. But only in release. Of course, everything “works” properly. :D

#ifndef _DEBUG
#define if(x) try{int _=*(int*)0;_=_;}catch(...){}if(x)
#endif

Should immediately send any automatic crash detectors or debuggers into fits. But only in release. Of course, everything “works” properly. :D

@lnaie

This comment has been minimized.

Show comment
Hide comment
@lnaie

lnaie Aug 19, 2015

reason to be shot on sight ;)

lnaie commented Aug 19, 2015

reason to be shot on sight ;)

@JessieArr

This comment has been minimized.

Show comment
Hide comment
@JessieArr

JessieArr Aug 19, 2015

// Fun with off-by-one errors:
#define > >=
#define < <=
#define == <=
// Fun with off-by-one errors:
#define > >=
#define < <=
#define == <=
@joineral32

This comment has been minimized.

Show comment
Hide comment
@joineral32

joineral32 Aug 19, 2015

I added a few I thought would be funny in a fork:
https://gist.github.com/joineral32/ba144be3a696f2d25c66

I added a few I thought would be funny in a fork:
https://gist.github.com/joineral32/ba144be3a696f2d25c66

@JamesBender

This comment has been minimized.

Show comment
Hide comment
@JamesBender

JamesBender Aug 19, 2015

I feel like I'm going to Hell just for reading this.

I feel like I'm going to Hell just for reading this.

@bagre

This comment has been minimized.

Show comment
Hide comment
@bagre

bagre Aug 19, 2015

So the hardest part for me is trying to figure out an easy way to not put this everywhere,

define main(x) do(main func signature); int main(x) {SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) exit); do(x)} int do(mainfuncsig){

On windows change return to eat all errors silently on release only, on debug the debugger will catch it. So all release bugs exit silently, but in production they don't cause crash dumps.

bagre commented Aug 19, 2015

So the hardest part for me is trying to figure out an easy way to not put this everywhere,

define main(x) do(main func signature); int main(x) {SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) exit); do(x)} int do(mainfuncsig){

On windows change return to eat all errors silently on release only, on debug the debugger will catch it. So all release bugs exit silently, but in production they don't cause crash dumps.

@zahirtezcan

This comment has been minimized.

Show comment
Hide comment
@zahirtezcan

zahirtezcan Aug 19, 2015

Build passes! ... well ... most of the time

Build passes! ... well ... most of the time

@tafryn

This comment has been minimized.

Show comment
Hide comment
@tafryn

tafryn Aug 19, 2015

Shouldn't these two blocks be !=0?

#define true ((__LINE__&15)!=15)
#define true ((rand()&15)!=15)

tafryn commented Aug 19, 2015

Shouldn't these two blocks be !=0?

#define true ((__LINE__&15)!=15)
#define true ((rand()&15)!=15)
@orionnoir

This comment has been minimized.

Show comment
Hide comment
@orionnoir

orionnoir Aug 19, 2015

Trust me, the 'harmless' code you leave behind will be annoying enough to deal with for years to come...

Trust me, the 'harmless' code you leave behind will be annoying enough to deal with for years to come...

@2shraaf

This comment has been minimized.

Show comment
Hide comment
@2shraaf

2shraaf Aug 19, 2015

#define j++ i++ 

2shraaf commented Aug 19, 2015

#define j++ i++ 
@miguelmota

This comment has been minimized.

Show comment
Hide comment

oh gawd..

@zerors

This comment has been minimized.

Show comment
Hide comment
@zerors

zerors Aug 19, 2015

define NULL "NULL"

zerors commented Aug 19, 2015

define NULL "NULL"

@petermelias

This comment has been minimized.

Show comment
Hide comment
@petermelias

petermelias Aug 19, 2015

#!/usr/bin/python27

# Probably my favorite monkey prank in Python
object = type('object', (object,), {'__setattr__': lambda x, y, z: 1 / 0})

# almost as frustrating but far too obvious
list = dict
#!/usr/bin/python27

# Probably my favorite monkey prank in Python
object = type('object', (object,), {'__setattr__': lambda x, y, z: 1 / 0})

# almost as frustrating but far too obvious
list = dict
@mokagio

This comment has been minimized.

Show comment
Hide comment

mokagio commented Aug 19, 2015

😱

@AlphaWhelp

This comment has been minimized.

Show comment
Hide comment
@AlphaWhelp

AlphaWhelp Aug 19, 2015

define return throw

have fun

define return throw

have fun

@robbyoconnor

This comment has been minimized.

Show comment
Hide comment
@robbyoconnor

robbyoconnor Aug 20, 2015

I love this.

I love this.

@kylemsguy

This comment has been minimized.

Show comment
Hide comment
@kylemsguy

kylemsguy Aug 20, 2015

#define M_PI 3.2f

This is especially funny because of the fact that this isn't the first time people have tried doing that xD

#define M_PI 3.2f

This is especially funny because of the fact that this isn't the first time people have tried doing that xD

@rreusser

This comment has been minimized.

Show comment
Hide comment
@rreusser

rreusser Aug 20, 2015

What about redistributing the random numbers? It'll only change behavior that's already stochastic… May eventually lead to nagging doubts of randomness…

// Still in [0,1) but with central tendencies:
#define drand48() (acos(1.0-2.0*drand48())/M_PI)

// Extra random:
#define rand() (rand() | rand())

If you use rand() % n with that last one, here's what you'll get for relative frequencies:

                     frequency relative to uniform distribution:
                0     1     2     3     4     5     6     7     8     9    10
          1:  1.00
          2:  0.50  1.50
          3:  1.00  1.00  1.00
          4:  0.25  0.75  0.75  2.25
rand() %  5:  1.00  1.00  1.00  1.00  1.00
          6:  0.50  1.50  0.50  1.50  0.50  1.50
          7:  1.00  1.00  1.00  1.00  1.00  1.00  1.00
          8:  0.12  0.37  0.37  1.13  0.37  1.12  1.12  3.38
          9:  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00
         10:  0.50  1.50  0.50  1.50  0.50  1.50  0.50  1.50  0.50  1.50
         11:  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00

What about redistributing the random numbers? It'll only change behavior that's already stochastic… May eventually lead to nagging doubts of randomness…

// Still in [0,1) but with central tendencies:
#define drand48() (acos(1.0-2.0*drand48())/M_PI)

// Extra random:
#define rand() (rand() | rand())

If you use rand() % n with that last one, here's what you'll get for relative frequencies:

                     frequency relative to uniform distribution:
                0     1     2     3     4     5     6     7     8     9    10
          1:  1.00
          2:  0.50  1.50
          3:  1.00  1.00  1.00
          4:  0.25  0.75  0.75  2.25
rand() %  5:  1.00  1.00  1.00  1.00  1.00
          6:  0.50  1.50  0.50  1.50  0.50  1.50
          7:  1.00  1.00  1.00  1.00  1.00  1.00  1.00
          8:  0.12  0.37  0.37  1.13  0.37  1.12  1.12  3.38
          9:  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00
         10:  0.50  1.50  0.50  1.50  0.50  1.50  0.50  1.50  0.50  1.50
         11:  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00  1.00
@liviutudor

This comment has been minimized.

Show comment
Hide comment
@liviutudor

liviutudor Aug 20, 2015

Bloody brilliant! In fact it looks very close to the kind of C++ code I use to write in college :D

Bloody brilliant! In fact it looks very close to the kind of C++ code I use to write in college :D

@BelfordZ

This comment has been minimized.

Show comment
Hide comment
@BelfordZ

BelfordZ Aug 20, 2015

@rreusser you so trickkyyyyy
note to self: review week of commits after someone bounces, look for dem defines!

@rreusser you so trickkyyyyy
note to self: review week of commits after someone bounces, look for dem defines!

@jep-dev

This comment has been minimized.

Show comment
Hide comment
@jep-dev

jep-dev Aug 20, 2015

Since endl is '\n'<<flush...

#define endl flush

jep-dev commented Aug 20, 2015

Since endl is '\n'<<flush...

#define endl flush
@SylvainDe

This comment has been minimized.

Show comment
Hide comment
@SylvainDe

SylvainDe Aug 20, 2015

I am surprised no one is mentioning the use of trigraphs ( https://en.wikipedia.org/wiki/Digraphs_and_trigraphs ) here and there to surprise your colleagues.

I am surprised no one is mentioning the use of trigraphs ( https://en.wikipedia.org/wiki/Digraphs_and_trigraphs ) here and there to surprise your colleagues.

@Spaown

This comment has been minimized.

Show comment
Hide comment
@Spaown

Spaown Aug 20, 2015

Woaw, this is terrorism xD

Spaown commented Aug 20, 2015

Woaw, this is terrorism xD

@auxiliary-character

This comment has been minimized.

Show comment
Hide comment
@auxiliary-character

auxiliary-character Aug 20, 2015

#define union struct
#define union struct
@bhurt

This comment has been minimized.

Show comment
Hide comment
@bhurt

bhurt Aug 20, 2015

My favorite C "gotcha":

define TRUE (2 & 3 == 2)

define FALSE (!TRUE)

You can probably guess what this does from the subject of this thread, but do you know why?

bhurt commented Aug 20, 2015

My favorite C "gotcha":

define TRUE (2 & 3 == 2)

define FALSE (!TRUE)

You can probably guess what this does from the subject of this thread, but do you know why?

@jotes

This comment has been minimized.

Show comment
Hide comment
@jotes

jotes Aug 20, 2015

The biggest fuckup here would be a lack of CI and testing.

jotes commented Aug 20, 2015

The biggest fuckup here would be a lack of CI and testing.

@cpavlina

This comment has been minimized.

Show comment
Hide comment
@cpavlina

cpavlina Aug 20, 2015

auxiliary-character, this one is more fun:

#define struct union

auxiliary-character, this one is more fun:

#define struct union
@ThePhantasm

This comment has been minimized.

Show comment
Hide comment
@ThePhantasm

ThePhantasm Aug 20, 2015

define volatile __declspec(thread)

define volatile __declspec(thread)

@LYF610400210

This comment has been minimized.

Show comment
Hide comment
@antte

This comment has been minimized.

Show comment
Hide comment
@antte

antte Aug 21, 2015

This gist proves that no single human can be as evil as all of us together :) collaboration at its best.

antte commented Aug 21, 2015

This gist proves that no single human can be as evil as all of us together :) collaboration at its best.

@EskenderTamrat

This comment has been minimized.

Show comment
Hide comment
@wojteklu

This comment has been minimized.

Show comment
Hide comment

pure evil

@xylcbd

This comment has been minimized.

Show comment
Hide comment
@xylcbd

xylcbd Aug 25, 2015

what's the best evil code ?

xylcbd commented Aug 25, 2015

what's the best evil code ?

@primary0

This comment has been minimized.

Show comment
Hide comment
@Dizmaz1

This comment has been minimized.

Show comment
Hide comment
@Dizmaz1

Dizmaz1 Sep 11, 2015

define continue break

Dizmaz1 commented Sep 11, 2015

define continue break

@Dracks

This comment has been minimized.

Show comment
Hide comment
@Dracks

Dracks Oct 7, 2015

@jotes The solution it's here: https://github.com/hmlb/phpunit-vw The VW CI module! :)

Dracks commented Oct 7, 2015

@jotes The solution it's here: https://github.com/hmlb/phpunit-vw The VW CI module! :)

@Gonzalo-Z

This comment has been minimized.

Show comment
Hide comment
@Gonzalo-Z

Gonzalo-Z Oct 9, 2015

Me as a QA Engineer reading this...

scared

Me as a QA Engineer reading this...

scared

@Alhadis

This comment has been minimized.

Show comment
Hide comment
@Alhadis

Alhadis Oct 24, 2015

This. Is. Brilliant.

Holy shit.

Alhadis commented Oct 24, 2015

This. Is. Brilliant.

Holy shit.

@shirlston

This comment has been minimized.

Show comment
Hide comment
@shirlston

shirlston Oct 24, 2015

My C is a little rusty, but I think this would break everything. (Hint: the second one isn't a semicolon)
#define ; ;

My C is a little rusty, but I think this would break everything. (Hint: the second one isn't a semicolon)
#define ; ;

@tokoroten

This comment has been minimized.

Show comment
Hide comment
@tokoroten

tokoroten Oct 29, 2015

#define long int // for non 32 bit env
#define long int // for non 32 bit env
@jimgao1

This comment has been minimized.

Show comment
Hide comment
@jimgao1

jimgao1 Oct 29, 2015

The look on his face when your friend discovered this....

jimgao1 commented Oct 29, 2015

The look on his face when your friend discovered this....

@felipou

This comment has been minimized.

Show comment
Hide comment
@felipou

felipou Nov 10, 2015

One can also do this to break a single computer:
alias g++="g++ -include /path/to/evil.h"
This way the source files and the repository remains intact... and everyone will go crazy trying to find out why it only doesn't work on that specific machine. Or those specific machines, if you can manage it.

felipou commented Nov 10, 2015

One can also do this to break a single computer:
alias g++="g++ -include /path/to/evil.h"
This way the source files and the repository remains intact... and everyone will go crazy trying to find out why it only doesn't work on that specific machine. Or those specific machines, if you can manage it.

@Ir1d

This comment has been minimized.

Show comment
Hide comment
@Ir1d

Ir1d Nov 26, 2015

@shirlston

Guess you would like to take a look at this.D

https://github.com/reinderien/mimic

Ir1d commented Nov 26, 2015

@shirlston

Guess you would like to take a look at this.D

https://github.com/reinderien/mimic

@finnoleary

This comment has been minimized.

Show comment
Hide comment
@finnoleary

finnoleary Dec 3, 2015

/* create memory leaks if run on April, 1st -- requires time.h (UNTESTED) */
#define free(n) if((date() - 777600) % 31556926 < 86400) malloc(n); else free(n)
/* create memory leaks if run on April, 1st -- requires time.h (UNTESTED) */
#define free(n) if((date() - 777600) % 31556926 < 86400) malloc(n); else free(n)
@ferrywon

This comment has been minimized.

Show comment
Hide comment
@ferrywon

ferrywon Jan 5, 2016

I'm your BOSS!!! Coming my office NOW !!!

ferrywon commented Jan 5, 2016

I'm your BOSS!!! Coming my office NOW !!!

@slashbinsh

This comment has been minimized.

Show comment
Hide comment
@slashbinsh

slashbinsh Jan 6, 2016

(True, False) = (False, True)

(True, False) = (False, True)

@fisher

This comment has been minimized.

Show comment
Hide comment
@fisher

fisher Jan 6, 2016

#define close(...) /* very special GC workaround */

fisher commented Jan 6, 2016

#define close(...) /* very special GC workaround */

@teschdominic

This comment has been minimized.

Show comment
Hide comment
@teschdominic

teschdominic Jan 10, 2016

what does this do

what does this do

@norbekaiser

This comment has been minimized.

Show comment
Hide comment
@norbekaiser

norbekaiser Mar 16, 2016

how about^

#ifdef EXIT_SUCCESS
  #undef EXIT_SUCCESS
#endif
  typedef void (*EXIT_SUCCESS)();

#ifdef EXIT_FAILURE
  #undef EXIT_FAILURE
#endif
  typedef void (*EXIT_FAILURE)();

how about^

#ifdef EXIT_SUCCESS
  #undef EXIT_SUCCESS
#endif
  typedef void (*EXIT_SUCCESS)();

#ifdef EXIT_FAILURE
  #undef EXIT_FAILURE
#endif
  typedef void (*EXIT_FAILURE)();

@Tatsh

This comment has been minimized.

Show comment
Hide comment
@Tatsh

Tatsh Mar 20, 2016

Somewhat easily detected but need some OS X/iOS/Objective-C stuff here:

// The obvious
#define YES NO

// Make the preprocessor think you're targeting a very early version of Foundation (probably has to be above #import)
#undef NSFoundationVersionNumber10_10
#define NSFoundationVersionNumber10_10 NSFoundationVersionNumber10_0

// Replace all immutable types with mutable!
#define NSArray NSMutableArray
#define NSDictionary NSMutableDictionary
#define NSSet NSMutableSet
#define NSData NSMutableData
// and so on

// Mess with memory
#define __weak

// Put your favourite exception message here
#define NSLog(m, ....) NSLog("Uncaught exception ...")

// Mess with transformations, possibly animations
#define GAffineTransformMake(a,b,c,d,tx,ty) GAffineTransformMake(a+1,a+2,c+3,d+4,tx-1,tx-2)

// Always return an error
#define SecItemCopyMatching(a, b) errSecNoSuchClass
// Useless error message
#define SecCopyErrorMessageString(a, b) CFSTR("Secret error")

Tatsh commented Mar 20, 2016

Somewhat easily detected but need some OS X/iOS/Objective-C stuff here:

// The obvious
#define YES NO

// Make the preprocessor think you're targeting a very early version of Foundation (probably has to be above #import)
#undef NSFoundationVersionNumber10_10
#define NSFoundationVersionNumber10_10 NSFoundationVersionNumber10_0

// Replace all immutable types with mutable!
#define NSArray NSMutableArray
#define NSDictionary NSMutableDictionary
#define NSSet NSMutableSet
#define NSData NSMutableData
// and so on

// Mess with memory
#define __weak

// Put your favourite exception message here
#define NSLog(m, ....) NSLog("Uncaught exception ...")

// Mess with transformations, possibly animations
#define GAffineTransformMake(a,b,c,d,tx,ty) GAffineTransformMake(a+1,a+2,c+3,d+4,tx-1,tx-2)

// Always return an error
#define SecItemCopyMatching(a, b) errSecNoSuchClass
// Useless error message
#define SecCopyErrorMessageString(a, b) CFSTR("Secret error")
@Redwan13

This comment has been minimized.

Show comment
Hide comment
@Redwan13

Redwan13 Mar 25, 2016

Things to commit just before leaving your job

Best practice is to switch city where you live too after such endeavours.

Things to commit just before leaving your job

Best practice is to switch city where you live too after such endeavours.

@ojno

This comment has been minimized.

Show comment
Hide comment
@ojno

ojno Mar 25, 2016

#ifdef DEBUG
#undef DEBUG
#endif

#ifdef NDEBUG
#undef NDEBUG
#endif

And so on...

ojno commented Mar 25, 2016

#ifdef DEBUG
#undef DEBUG
#endif

#ifdef NDEBUG
#undef NDEBUG
#endif

And so on...

@cdevr

This comment has been minimized.

Show comment
Hide comment
@cdevr

cdevr Apr 8, 2016

class ThereIsNoAbsoluteTruth:
def nonzero(self):
import random
return random.randint(1, 1000) < 1000
def str(self):
return "True"
def repr(self):
return "True"

True = ThereIsNoAbsoluteTruth()

cdevr commented Apr 8, 2016

class ThereIsNoAbsoluteTruth:
def nonzero(self):
import random
return random.randint(1, 1000) < 1000
def str(self):
return "True"
def repr(self):
return "True"

True = ThereIsNoAbsoluteTruth()

@Link512

This comment has been minimized.

Show comment
Hide comment
@Link512

Link512 Apr 8, 2016

ifndef DEBUG

define true false

endif

Same stuff with NDEBUG. The idea is only to do this in release mode.

Link512 commented Apr 8, 2016

ifndef DEBUG

define true false

endif

Same stuff with NDEBUG. The idea is only to do this in release mode.

@mabm

This comment has been minimized.

Show comment
Hide comment
@mabm

mabm Apr 9, 2016

Wahoo .. You are my hero +1

mabm commented Apr 9, 2016

Wahoo .. You are my hero +1

@llxp

This comment has been minimized.

Show comment
Hide comment
@llxp

llxp Apr 9, 2016

How about wrapping a system dll under Windows and putting some of this evil stuff in it xD

llxp commented Apr 9, 2016

How about wrapping a system dll under Windows and putting some of this evil stuff in it xD

@macedigital

This comment has been minimized.

Show comment
Hide comment
@macedigital

macedigital Apr 20, 2016

Holy crap! And I thought operator overloading (e.g. http://stackoverflow.com/questions/1098303/what-makes-scalas-operator-overloading-good-but-cs-bad) was crazy 🙈 All hail the macro 😄

Holy crap! And I thought operator overloading (e.g. http://stackoverflow.com/questions/1098303/what-makes-scalas-operator-overloading-good-but-cs-bad) was crazy 🙈 All hail the macro 😄

@hanbang-wang

This comment has been minimized.

Show comment
Hide comment
@hanbang-wang

hanbang-wang Apr 27, 2016

The random part truly works most of the time (don't ask me why I know it

The random part truly works most of the time (don't ask me why I know it

@lovemo

This comment has been minimized.

Show comment
Hide comment
@lovemo

lovemo Apr 28, 2016

crazy 😄

lovemo commented Apr 28, 2016

crazy 😄

@seven1240

This comment has been minimized.

Show comment
Hide comment

Cool

@nellochen

This comment has been minimized.

Show comment
Hide comment
@nellochen

nellochen Apr 29, 2016

never say a word...

never say a word...

@wangrenjun

This comment has been minimized.

Show comment
Hide comment
@wangrenjun

wangrenjun May 3, 2016

undef __cplusplus

undef __cplusplus

@msierchio

This comment has been minimized.

Show comment
Hide comment
@msierchio

msierchio Jun 30, 2016

A thing of beauty is a joy forever.

A thing of beauty is a joy forever.

@roman-alexeev

This comment has been minimized.

Show comment
Hide comment
@roman-alexeev

roman-alexeev Aug 10, 2016

#define __STDLIB_H__ 1

roman-alexeev commented Aug 10, 2016

#define __STDLIB_H__ 1

@wizard97

This comment has been minimized.

Show comment
Hide comment
@wizard97

wizard97 Aug 14, 2016

#define sizeof(x) sizeof(x)+1

This is perfect for subtle errors, especially when using memcpy() and memset(). Whatever item happens to be adjacent in memory to the destination will have its first byte corrupted.

#define sizeof(x) sizeof(x)+1

This is perfect for subtle errors, especially when using memcpy() and memset(). Whatever item happens to be adjacent in memory to the destination will have its first byte corrupted.

@wizard97

This comment has been minimized.

Show comment
Hide comment
@wizard97

wizard97 Aug 14, 2016

static jmp_buf _evil;

#define if(x) setjmp(_evil); if(x)
// Redefine some keywords :)
#define break do { if(rand() > RAND_MAX * 0.99) longjmp(_evil, 1); break; } while(0)
#define continue do { if(rand() > RAND_MAX * 0.99) longjmp(_evil, 1); continue; } while(0)

Ahh, random occasional longjmps that could do one of several things:

  1. Jump to the last time an if statement was executed
  2. Jump into a call frame that no longer exists causing undefined behavior
  3. Segfault

wizard97 commented Aug 14, 2016

static jmp_buf _evil;

#define if(x) setjmp(_evil); if(x)
// Redefine some keywords :)
#define break do { if(rand() > RAND_MAX * 0.99) longjmp(_evil, 1); break; } while(0)
#define continue do { if(rand() > RAND_MAX * 0.99) longjmp(_evil, 1); continue; } while(0)

Ahh, random occasional longjmps that could do one of several things:

  1. Jump to the last time an if statement was executed
  2. Jump into a call frame that no longer exists causing undefined behavior
  3. Segfault
@kvpb

This comment has been minimized.

Show comment
Hide comment
@kvpb

kvpb Aug 22, 2016

I find you guys rather stingy with your future former colleagues. Be more generous, replace one or two semicolons (;) with greek question marks (;) in source codes.

screenshot 2016-08-22 at 15 03 43

screenshot 2016-08-22 at 15 03 53

Though some compilers might help spot this, it should work as long as error messages don't make it look too obvious. Don't mention it. You'll thank me later.

kvpb commented Aug 22, 2016

I find you guys rather stingy with your future former colleagues. Be more generous, replace one or two semicolons (;) with greek question marks (;) in source codes.

screenshot 2016-08-22 at 15 03 43

screenshot 2016-08-22 at 15 03 53

Though some compilers might help spot this, it should work as long as error messages don't make it look too obvious. Don't mention it. You'll thank me later.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Sep 12, 2016

Tears of joy .. Brilliant

ghost commented Sep 12, 2016

Tears of joy .. Brilliant

@onlurking

This comment has been minimized.

Show comment
Hide comment
@onlurking

onlurking Nov 12, 2016

Awesome production code, buddy.

Awesome production code, buddy.

@michaellee8

This comment has been minimized.

Show comment
Hide comment
@michaellee8

michaellee8 Dec 4, 2016

how about

#define == =

how about

#define == =

@jokester

This comment has been minimized.

Show comment
Hide comment
@jokester

jokester Dec 9, 2016

#define << >>

jokester commented Dec 9, 2016

#define << >>

@sergeysychov

This comment has been minimized.

Show comment
Hide comment
@sergeysychov

sergeysychov Dec 16, 2016

void __cxa_allocate_exception() { /*do nothing*/ }
void __cxa_throw() { /*do nothing*/ }

No exceptions = no problems

sergeysychov commented Dec 16, 2016

void __cxa_allocate_exception() { /*do nothing*/ }
void __cxa_throw() { /*do nothing*/ }

No exceptions = no problems

@TheRoyalGhost

This comment has been minimized.

Show comment
Hide comment
@TheRoyalGhost

TheRoyalGhost Dec 29, 2016

#define True False
#define False True
#define void Null

#define True False
#define False True
#define void Null

@JanWosnitza

This comment has been minimized.

Show comment
Hide comment
@JanWosnitza

JanWosnitza Apr 25, 2017

#define rand() (__LINE__ ^ (*static_cast<int*>(__TIME__.[4]))

JanWosnitza commented Apr 25, 2017

#define rand() (__LINE__ ^ (*static_cast<int*>(__TIME__.[4]))
@WestFive

This comment has been minimized.

Show comment
Hide comment
@WestFive

WestFive Apr 26, 2017

img

interesting

WestFive commented Apr 26, 2017

img

interesting

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost May 25, 2017

//insert super complex code that does important work
int main() {
  return 0;
} //sneak this in :smile 
//actual code

or even better

//insert super complex code that does important work
using namespace std;
#define cout cin
#define cin cout 
//actual code

or the good old variable name trick:

//insert important code
int foo;
int bar;
int temp;
int stuff;
int a;
int b;
int c;
int d;
int e;
//etc
//more important code

Time consuming, but definitely will make people angry.
Put this in a local scope to make people very angry.

ghost commented May 25, 2017

//insert super complex code that does important work
int main() {
  return 0;
} //sneak this in :smile 
//actual code

or even better

//insert super complex code that does important work
using namespace std;
#define cout cin
#define cin cout 
//actual code

or the good old variable name trick:

//insert important code
int foo;
int bar;
int temp;
int stuff;
int a;
int b;
int c;
int d;
int e;
//etc
//more important code

Time consuming, but definitely will make people angry.
Put this in a local scope to make people very angry.

@AndrewDavis

This comment has been minimized.

Show comment
Hide comment
@AndrewDavis

AndrewDavis Jul 28, 2017

My favorites + some of my own alterations (for c++):

#ifndef DEBUG
#define if(x) if (x && (__LINE__ % 6 == 0 && rand() % 1000 == 0)) //On rare occasion, any if statements on every 6 lines of code should fail.
#define j (rand() % 1000 == 0 ? i : j) //Should never use these anyways... Usually j is used in the inner loop.
#define union struct //Still "runs"...
#define double float //Efficiency, no?
#define delete //!!!NEIN!!!
#endif

(Note: upon a later glance, I had doubts that the #define j will work; but, according to this link, it will: https://stackoverflow.com/questions/11494988/using-ternary-operator-to-initialize-a-reference-variable)

AndrewDavis commented Jul 28, 2017

My favorites + some of my own alterations (for c++):

#ifndef DEBUG
#define if(x) if (x && (__LINE__ % 6 == 0 && rand() % 1000 == 0)) //On rare occasion, any if statements on every 6 lines of code should fail.
#define j (rand() % 1000 == 0 ? i : j) //Should never use these anyways... Usually j is used in the inner loop.
#define union struct //Still "runs"...
#define double float //Efficiency, no?
#define delete //!!!NEIN!!!
#endif

(Note: upon a later glance, I had doubts that the #define j will work; but, according to this link, it will: https://stackoverflow.com/questions/11494988/using-ternary-operator-to-initialize-a-reference-variable)

@rjamesnw

This comment has been minimized.

Show comment
Hide comment

lol

@michaellee8

This comment has been minimized.

Show comment
Hide comment
@michaellee8

michaellee8 Nov 4, 2017

Any JavaScript/node.js version for this? Xdd

Any JavaScript/node.js version for this? Xdd

@Fer0x

This comment has been minimized.

Show comment
Hide comment

Fer0x commented Nov 21, 2017

image

@twoscomplement

This comment has been minimized.

Show comment
Hide comment
@twoscomplement

twoscomplement Feb 2, 2018

Runtime randomness is great, but have you considered adding a compile time RNG? ;)

Runtime randomness is great, but have you considered adding a compile time RNG? ;)

@ramonsaraiva

This comment has been minimized.

Show comment
Hide comment
@ramonsaraiva

ramonsaraiva Feb 22, 2018

https://github.com/ramonsaraiva/init python thingy inspired by this 😄

https://github.com/ramonsaraiva/init python thingy inspired by this 😄

@johnbsys

This comment has been minimized.

Show comment
Hide comment
@knyzorg

This comment has been minimized.

Show comment
Hide comment
@knyzorg

knyzorg May 24, 2018

ITT: people who don't know how to code block

knyzorg commented May 24, 2018

ITT: people who don't know how to code block

@AnrDaemon

This comment has been minimized.

Show comment
Hide comment
@AnrDaemon

AnrDaemon Jun 15, 2018

Reminds me why do you need CI and tests.

Reminds me why do you need CI and tests.

@drewchapin

This comment has been minimized.

Show comment
Hide comment
@drewchapin

drewchapin Jun 29, 2018

What would be really fun would be placing them in <Windows.h> on the developer machines and build server(s). Use conflicting #defines randomly between each so that the effects are different depending on who's compiling the code.

drewchapin commented Jun 29, 2018

What would be really fun would be placing them in <Windows.h> on the developer machines and build server(s). Use conflicting #defines randomly between each so that the effects are different depending on who's compiling the code.

@tigerssj

This comment has been minimized.

Show comment
Hide comment
@tigerssj

tigerssj Jul 6, 2018

your boss loves you....

tigerssj commented Jul 6, 2018

your boss loves you....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment