This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef ATOMIC_H | |
#define ATOMIC_H | |
// Adapted from http://golubenco.org/2007/06/14/atomic-operations | |
/** | |
* @brief Atomic type | |
*/ | |
typedef int atomic_t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <RCCE.h> | |
#include "timer.h" | |
#define PRINT(...) { printf(__VA_ARGS__); fflush(stdout); } | |
#define CORE(i) if (RCCE_ue() == (i)) | |
#define MSG_SIZE 32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <RCCE.h> | |
#include "timer.h" | |
#define PRINT(...) { printf(__VA_ARGS__); fflush(stdout); } | |
#define CORE(i) if (RCCE_ue() == (i)) | |
#define MSG_SIZE 32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define vm(args...) \ | |
do { \ | |
/* Check if argument list is empty */ \ | |
if (#args[0] == '\0') { \ | |
printf("Argument list is empty\n"); \ | |
} else { \ | |
printf("Argument list is \"%s\"\n", #args); \ | |
} \ | |
} while (0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// RUN: cc -Wall -Wextra %s && ./a.out | |
#include <assert.h> | |
#if defined(__GNUC__) || defined(__clang__) | |
// Supports 0-10 arguments | |
#define VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N | |
// ## deletes preceding comma if _VA_ARGS__ is empty (GCC, Clang) | |
#define VA_NARGS(...) VA_NARGS_IMPL(_, ## __VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) | |
#else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdbool.h> | |
#include <string.h> | |
#include "async.h" | |
typedef struct { | |
void *fn; // pointer to piece of code | |
unsigned char data[128]; // data environment | |
} Task; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
/* Count variadic macro arguments (1-10 arguments, extend as needed) | |
*/ | |
#define VA_NARGS_IMPL(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N | |
#define VA_NARGS(...) VA_NARGS_IMPL(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) | |
/* Simple name mangling of function sum based on arity | |
*/ | |
#define __sum_impl2(n, ...) __sum_impl__ ## n(__VA_ARGS__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef OVERLOAD__FN__H | |
#define OVERLOAD__FN__H | |
#ifndef VA_NARGS | |
/* Count variadic macro arguments (1-10 arguments, extend as needed) | |
*/ | |
#define VA_NARGS_IMPL(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N | |
#define VA_NARGS(...) VA_NARGS_IMPL(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
struct rectangle { | |
double x1, x2, y1, y2; | |
}; | |
double area(struct rectangle r) | |
{ | |
return (r.x2 - r.x1) * (r.y2 - r.y1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
// Make sure that before is executed before a dependent block or statement | |
// and after is executed afterwards | |
#define PROTECTED(before, after) \ | |
for (int __i = ((before), 0); !__i; (after), __i++) | |
int main(void) |