I'm wondering if the compiler/linker will remove global variables that have been extern
'd in a public header? For example:
// public.h
struct func_ptrs {
void (*foo)(void);
void (*bar)(int);
};
extern const struct func_ptrs DEFAULT_FUNCS;
and:
// private.c
#include "public.h"
void def_foo(void) { ... }
void def_bar(int a) { ... }
const struct func_ptrs DEFAULT_FUNCS = { .foo = def_foo, .bar = def_bar };
Are there any specific linker flags that will allow for this variable (and the two functions) to be stripped from the resulting binary?
Assume GCC and MSVC as the two target compilers.