Skip to content

Instantly share code, notes, and snippets.

@unveres
unveres / generator.h
Last active January 28, 2020 12:08
example showing how easily generators can be achieved in C, it's the shortest way, however it is not flawless
#ifndef _GENERATOR_H
#define _GENERATOR_H
#include <setjmp.h>
#define GENERATOR_BEGIN() \
static jmp_buf _generator_step, \
_generator_beginning; \
static int _generator_is_first_use = 1; \
\
if (_generator_is_first_use) { \
@unveres
unveres / printf_example_progressbar.c
Last active July 15, 2018 10:41
example showing really powerful capabilities of printf, here it is a progress bar
#include <stdio.h>
#include <string.h>
#include <unistd.h>
/* printf example: progress bar */
/* by unveres, 2018 */
/* more at gist.github.com/unveres */
/* look at that 25th line of code, it shows the true power of printf */
#define BARSIZE (50)