I'm wondering how visibility is granted to one file while being restricted in another.
Say I have a function 'void second_hello()' which is defined in the second.c file and I want that to be available in the first.c file but not in the main.c file.. Basically I want to call a function in first.c which calls the function in second.c because I want the function in second.c hidden from main.c. Hope that makes sense.
Here's what I tried.
second.h
Code:
#ifndef SECOND__HH
#define SECOND__HH
void second_hello();
#endif
second.c
Code:
#include <stdio.h>
#include "second.h"
void second_hello() {//this should only be available in first.c
fputs("Hello world from the second!\n", stdout);
}
first.h
Code:
#ifndef FIRST__HH
#define FIRST__HH
void first_hello();
#endif
first.c
Code:
#include "first.h"
#include "second.h"
void first_hello() {
second_hello();
}
main.c
Code:
#include <stdio.h>
#include "first.h"
int main(int argc, char ** argv) {
first_hello();//which calls second_hello()
return 0;
}
Is the above code a proper way to restrict visibility of 'void second_hello()'?