Skip to content

Instantly share code, notes, and snippets.

View Warwolt's full-sized avatar

Rasmus Källqvist Warwolt

  • Mojang Studios
  • Stockholm
View GitHub Profile
/**
* @brief Example of implementing closure like data structures in C.
*
* The idea is to create a function equivalent to a 'fat pointer', a pointer
* with added meta data. In this case, the meta data contains the values that
* are captured in the function that constructs and returns the closure, and
* since there are no lambdas we instead point to an already defined function,
* that takes a closure instance as argument.
*
* Reference python code:
@Warwolt
Warwolt / main.c
Last active January 11, 2020 20:47
Example usage of closure header in C
/**
* A tiny language experiment, defining closures in C.
* The reference python-code that is implemented:
*
* def add(a):
* return (lambda b: a + b)
*
* def main():
* c = add(5)
* print('c(10) =', c(10))
# root @ DESKTOP-45OSPTR in ~/code/c/objects/object_stuff1 on git:master x [23:50:50]
$ echo $LS_COLORS
rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=34:ow=34:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;3
import sys
def main():
testcases_file = open("testcases.txt", "r")
for line in testcases_file:
print_non_comment_line(line)
def print_non_comment_line(line):
if (line[0] != '#'):
stripped_line = line.lstrip()
class Counter
{
public:
void count() { counter++; }
int getCount() { return counter; }
private:
int counter = 0;
};
static void(*funcptr)(void) = nullptr;
struct Point
{
int x;
int y;
};
translate_point_diagonally(Point *p, int amount)
{
p->x += amount;
p->y += amount;
void add_num(int num)
{
num += 1;
}
void add_num_ptr(int* num)
{
*num += 1;
}