Skip to content

Instantly share code, notes, and snippets.

@zed
Created March 29, 2010 02:18
Show Gist options
  • Save zed/347279 to your computer and use it in GitHub Desktop.
Save zed/347279 to your computer and use it in GitHub Desktop.
#include <assert.h>
#include <stdio.h>
enum { N = 10 };
static void inc(int* static_out, int* out){
static int static_var = 0;
int var = 0;
++static_var;
++var;
printf("static_var=%d, var=%d\n", static_var, var);
*static_out = static_var;
*out = var;
}
int main(void) {
int i = 0;
int ret = -1;
int static_ret = -1;
for ( ; i < N; ++i)
inc(&static_ret, &ret);
assert(ret == 1);
assert(static_ret == N);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment