Skip to content

Instantly share code, notes, and snippets.

@lightdiscord
Created July 9, 2021 12:54
Show Gist options
  • Save lightdiscord/2812773dcc334c5fcb541c69c9d62271 to your computer and use it in GitHub Desktop.
Save lightdiscord/2812773dcc334c5fcb541c69c9d62271 to your computer and use it in GitHub Desktop.

POC: Duplication of variable in headers

$ gcc -o a.out *.c && ./a.out
one: 4
two: 4
one: 42
two: 4
#ifndef HEADER_H
# define HEADER_H
static int value = 4;
#endif
#include <stdio.h>
#include "header.h"
void checkValue(void);
int main(void) {
printf("one: %d\n", value);
checkValue();
value = 42;
printf("one: %d\n", value);
checkValue();
}
#include <stdio.h>
#include "header.h"
void checkValue(void) {
printf("two: %d\n", value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment