Skip to content

Instantly share code, notes, and snippets.

@MadCoder
Created December 7, 2016 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MadCoder/0a6f87938b17f197f682e837a53722a8 to your computer and use it in GitHub Desktop.
Save MadCoder/0a6f87938b17f197f682e837a53722a8 to your computer and use it in GitHub Desktop.
Horrible C Scope abuse
#include <stdio.h>
#include <stdlib.h>
void
invalid_code(void)
{
void (^block)(void);
if (rand() % 2) {
block = ^{ printf("odd\n"); };
} else {
block = ^{ printf("even\n"); };
}
block();
}
void
valid_code(void)
{
void (^block)(void);
if (rand() % 2)
block = ^{ printf("odd\n"); };
else
block = ^{ printf("even\n"); };
block();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment