Skip to content

Instantly share code, notes, and snippets.

@aras-p
Last active June 7, 2026 14:44
Show Gist options
  • Select an option

  • Save aras-p/6224951 to your computer and use it in GitHub Desktop.

Select an option

Save aras-p/6224951 to your computer and use it in GitHub Desktop.
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
@advnpzn

advnpzn commented Sep 1, 2021

Copy link
Copy Markdown

@notPlasticCat Try detector rails attached to powered rails

Thank you! I will ask if I get any doubts. ☺️

@sophuric

sophuric commented Sep 3, 2021

Copy link
Copy Markdown

mhm yes minecraft very related to this post lol

@JosephCatrambone

Copy link
Copy Markdown

#define free(p) realloc(p, 1)

@boomer41

Copy link
Copy Markdown

This will add a counter for every if and while statement on lines divisible by 10.
For each invocation of the if/while, the counter goes up by 1. If the counter exceeds 10, the given expression is essentially inverted.

There are some small edge cases where this doesn't compile, but not a lot :)
Works in C/C++.

#define if(_x) \
    if ( \
        ( \
            (__LINE__%10)==0 && \
            ({ \
                static int ___I_AM_EVIL = 0; \
                ___I_AM_EVIL++; \
                (___I_AM_EVIL > 10); \
            }) \
        ) \
        ^ (_x))

#define while(_x) \
    while ( \
        ( \
            (__LINE__%10)==0 && \
            ({ \
                static int ___I_AM_EVIL = 0; \
                ___I_AM_EVIL++; \
                (___I_AM_EVIL > 10); \
            }) \
        ) \
        ^ (_x))

@dkfellows

Copy link
Copy Markdown

Can anyone think of something involving setjmp and longjmp? Trying to figure out something doable

Absolutely anything involving them is already excessively evil. Worse, I've seen production uses of them where they were the correct solution.

@antoniwalburg

Copy link
Copy Markdown

**Shameless you guys**

@Exmantion

Exmantion commented Dec 13, 2022

Copy link
Copy Markdown

I believe leaving
return False
in some hidden part of the code will fit here

@Starmania

Copy link
Copy Markdown

How to automate carts using redstone in minecraft ? Any help ?

Why are you doing here

@keithpl

keithpl commented May 3, 2023

Copy link
Copy Markdown
#undef printf
#define printf(...) fprintf(stderr, __VA_ARGS__)

@JJL772

JJL772 commented May 30, 2023

Copy link
Copy Markdown

Microsoft's STL will check for keyword redefinitions: https://github.com/microsoft/STL/blob/main/stl/inc/xkeycheck.h

#define _XKEYCHECK_H will ensure it never gets included though 😉

@sophuric

sophuric commented May 31, 2023

Copy link
Copy Markdown
#define exit(x) while(1)malloc(1000)

@maximal

maximal commented May 31, 2023

Copy link
Copy Markdown

@mekb-turtle, wow, that’s quite good!

ghost commented Jul 8, 2023

Copy link
Copy Markdown
#define malloc(x) alloca(x * (1 << 15)) 

Have fun smashing some stacks on heap allocations. :)

@Firsto

Firsto commented Aug 29, 2023

Copy link
Copy Markdown

why so cruel

@PackmanDude

Copy link
Copy Markdown

lmao

ghost commented Sep 27, 2023

Copy link
Copy Markdown

lmao
oh you got me i actually tested that. good job, outplayed me 👍

@0xae

0xae commented Oct 18, 2023

Copy link
Copy Markdown

lmao lmao

That's pure evill, pure.

@sophuric

Copy link
Copy Markdown
#define malloc(x) malloc((x)-__LINE__)

ghost commented Jan 29, 2024

Copy link
Copy Markdown
#define malloc(x) malloc((x)-((rand()%100<98)?0:1))

@sophuric

sophuric commented Feb 2, 2024

Copy link
Copy Markdown
#define malloc(x) alloca(x * (1 << 15)) 

Have fun smashing some stacks on heap allocations. :)

#define malloc(x) malloc((x)-1)

@Stenzel

Stenzel commented Feb 2, 2024

Copy link
Copy Markdown

#define auto char

@Jacoblightning

Copy link
Copy Markdown

Some good ones I made

// ReSharper disable CppUnusedIncludeDirective

#pragma once

// This file is INTENDED to be evil.


// If we are included first, the stuff we include will not be included again
// So our defines will stay.

// If not, we will undef them anyway.

// It's a win-win

# include <stdlib.h>
#include <stdnoreturn.h>
#include <setjmp.h>


void noreturn __stack_chk_fail(void); // NOLINT(*-reserved-identifier)

#undef NULL
#define NULL (__stack_chk_fail(),((void*) 0))


// We need a jump buffer for more evil operations in the future.
#define int static jmp_buf _jbuf; \
    int

// Also invoke side effects here.
#define if(orig) if(setjmp(_jbuf),((orig)&&(orig)))

#define else longjmp(_jbuf, 1);

@justcoredev

Copy link
Copy Markdown

Ok thats evil

@gardenofnumbers

gardenofnumbers commented Jun 26, 2025

Copy link
Copy Markdown
#define pthread_create(thr, attr, f, arg) do { 
*thr = clone(f, mmap(0, 0x8000, PROT_READ|PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_GROWSDOWN, -1, 0) + 0x8000, CLONE_THREAD | CLONE_VM | CLONE_FILES | CLONE_SIGHAND, 0,0,0);
 } while(0)

This will cause spurious racy failures inside of various libc functions (such as malloc) due to not properly setting up thread local storage for each new thread.

@Crest

Crest commented Dec 3, 2025

Copy link
Copy Markdown

Now that is just mean.

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