Skip to content

Instantly share code, notes, and snippets.

@jleeothon
Created November 2, 2014 20:41
Show Gist options
  • Save jleeothon/5fcc7d98191a2b8449f0 to your computer and use it in GitHub Desktop.
Save jleeothon/5fcc7d98191a2b8449f0 to your computer and use it in GitHub Desktop.
Simple stack in C
/* for any stack in the form... */
int _s[100];
int *s = _s; /* top of the pending stack (this location empty) */
/* be very careful about passing expressions for a stack, not well guarded */
#define isempty(s) ((s) - (_s))
#define push(s, v) (*s++ = (v))
#define pop(s) (*(--s))
#define peek(s) ((s)[-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment