Namespace or packages in c-modules

I am starting a level c programmer from high level languages ​​and feel that c has a flat structure. There is some way to simulate packages, so I can have a clean namespace without requiring prefixes.

Nested structures are what I'm looking for.

How it works with external libraries of third-party developers, what happens when there is a name conflict or it is separate.

In case I need to create a library or multimode application related to libs so that each module can have the names of variables, functions or structures that are the same as in another module.

Also, if you link two third-party libraries (.a file, etc.) that have conflicting names, how do you resolve such conflicts.

0
source share
1 answer

Well, technically not, there is no way to have namespaces in the exact same way that C ++ does. Unfortunately, this leads to things like SDL2, which gives each function "SDL_". There is one solution to resolving conflicts between external libraries. Say we have a libfoo library that has a function

void do_foo(void *); 

defined. You are trying to compile and link your program, but it turns out that the other library that you use, "libfu", also has this function. Now I would like to create some adapter library that renames the function with the corresponding prefix. So we will have the file "libfoo_f.h" that defines the function

 void FOO_do_foo(void *); 

and in "libfoo_f.c"

 #include"libfoo_f.h" #include<libfoo.h> void FOO_do_foo(void *data) { do_foo(data); } 

All this function provides a way to access libfoo do_foo without breaking your libraries. Honestly, I never had to do this because most libraries have well-structured, well-named interfaces that are hardly in conflict with other libraries.

0
source

All Articles