Is it possible in some way to have separate namespaces between separate C files and have only those declarations that are in the header files be "public". For instance, the following example is how I would like it to work (but it doesn't).
Code:
/* foo.h */
void say_hello(void);
Code:
/* foo.c */
#include <stdio.h>
#include "foo.h"
void print_hello(void);
void print_world(void);
void say_hello(void)
{
print_hello();
print_world();
}
void print_hello(void)
{
printf("hello");
}
void print_world(void)
{
puts(" world");
}
Code:
/* main.c */
#include <stdio.h>
#include "foo.h"
/* print_hello and print_world have not been
declared as far as main.c can see */
int main(void)
{
say_hello();
return 0;
}
In main the functions print_hello and print_world cannot be used because they have not been declared. But main also cannot define functions of the same name of its own without raising the error "multiple definition" (when main.c and foo.c and compiled together, which they have to be, right?).
If anyone else has some ideas for how this might be accomplished please let me know. Or am I just stuck with a global namespace?