Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sv_inner.h:
- static int sv;
- static int sv_changed;
- static void init_sv(void);
- sv.h:
- int get_sv(void);
- void set_sv(int);
- void update_sv(void);
- sv.c:
- #include <stdbool.h>
- #include "sv.h"
- #include "sv_inner.h"
- static void init_sv(void) { static bool already = false; if (already) { return; } sv = sv_changed = 0; already = true; }
- int get_sv(void) { init_sv(); return sv; }
- void set_sv(int val) { init_sv(); sv_changed = val; }
- void update_sv(void) { init_sv(); sv = sv_changed; }
- main.c:
- #include <stdio.h>
- #include "sv.h"
- int main(void) {
- printf("sv = %d\n", get_sv());
- set_sv(100); printf("set_sv(100); sv = %d\n", get_sv());
- set_sv(10); printf("set_sv(10); sv = %d\n", get_sv());
- update_sv(); printf("update_sv(); sv = %d\n", get_sv());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement