Search code examples
cnaming-conventionsheader-filesnaming

C naming sub-module functions


It may be a little off-topic, and also heavily opinion-based, but I think the following problem deserves discussion:

Let say you are working on a bigger project, which consist of multiple files and multiple headers. For example you have a file(sub-module) which does save management, the other handles drawing and so on. What do you think is the best way of naming the functions inside a sub-module?

I would like something that I can see from that which file was the function declared/implemented in, which would help a lot during development and bugfixing.

My current approach:

  • Prefix every function with the name of the header it was declared in, example(functions declared in header save.h): save_load_savefile();, save_save_game();,etc.

Do you know any other, possibly better alternatives?


Solution

  • One idea would be to create a (static) struct per sub-module that has function pointers as elements. A call would look something like:

    fileSave.load_savefile()
    

    In this way you're moving a little bit in the direction of C++. You could of course also decide to use C++ in a light way, and create classes.