I have a C file in which a function is defined as
static int waves_selected(...){
}
So that it is only visible in this file.
However, it takes up a lot of screen real estate making it difficult to reverse engineer the code.
How can I put it in a separate file ands still only make it visible within this file that it was originally part of (callback.c)?
Pass 1 :
Create new file with the function, declare it as static there. This new .c also includes the .h. In the same .c, define a wrapper function. Only the wrapper function is declared in the .h. callback.c can now use this new header file.
Works? No, because other files that include this header file can use this wrapper. Please!
Pass 2 :
That sounds a bit messy. Is there some way we can do it using preprocessor directives?
Yes, define CALLBACK_C in the C file and check for that in the header file to hide the declaration
// callback_helpers.h
#ifndef CALLBACK_HELPERS_H
#define CALLBACK_HELPERS_H
#ifdef CALLBACK_C
int waves_selected(...); // Only exposed when CALLBACK_C is defined
#endif
#endif
No comments:
Post a Comment