Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
"Private to subproject" functions and variables
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Jack Klein, post: 2485227"] There is absolutely no way to prevent deliberate abuse, and indeed that is not the purpose of the C language. But there is a way to prevent accidental clashes, if that is what you are trying to do. Simply use name spaces. What are name spaces in C? A very simple concept. Everything in a "module" (or "task", or whatever you choose to call your code breakdown) that has external linkage starts with a prefix derived from the name of the module (task, whatever). So all the functions, external objects, and types declared or defined in mod1.h start with a specific prefix, such as m1_. struct m1_data_t { /* members */ }; enum { M1_OK, M1_MEMORY_ERROR, M1_FILE_NOT_FOUND, /* etc */ } m1_result_t; m1_result_t m1_regurtitate_data(int index, struct m1_data_t *data_ptr); ....and so on. And of course everything in mod2.h is prefixed with m2_, or mod2_, or whatever. As for symbols with external linkage within the source files of a module itself, they follow exactly the same naming convention, and are in headers used only within the source files of the module itself. On the other hand, if you are looking for a way to prevent a programmer writing code for mod2 from looking into an internal header for mod1 that declares: extern struct m1_data_t *m1_head; ....and copying the declaration to his own file so he can access m1_head directly, C cannot prevent that. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
"Private to subproject" functions and variables
Top