Skip to content

Instantly share code, notes, and snippets.

View MadCoder's full-sized avatar

Pierre Habouzit MadCoder

View GitHub Profile
@MadCoder
MadCoder / horrible-c-scope-abuse.c
Created December 7, 2016 02:23
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 {
__attribute__((warn_unused_result))
id my_func(int a, int b, int c);
#define my_func(a, b, c) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic error \"-Wunused-result\"") \
my_func(a, b, c) \
_Pragma("clang diagnostic pop")
@implementation MyClass
+ (instancetype)sharedInstanceWithError:(NSError **)error
{
static _Atomic(MyClass *) sMyClass;
MyClass *tmp = nil, *expected = nil;
#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__)
// this assumes that this platform has consume ordering
// for loads through dereferencing pointers, which both intel & arm have.
@MadCoder
MadCoder / is_even.c
Last active September 8, 2015 20:56
bool is_even(unsigned n)
{
char buf[11];
sprintf(buf, "%10u", n);
switch (buf[9]) {
case '0': return true;
case '1': return false;
default: return is_even(buf[9]);
}