How to structure your c program?

c

Solution

Some thoughts (and this question should be a community wiki)

- Even if it's not fully-fledged object-oriented programming, try to stick to information hiding practices. Let your functions return pointers or handles to opaque structures (the unix file handle api is a good (early) example. Use `static` functions where you'd otherwise use `private` methods.

- Try to keep related functionality contained to a single file. This will make it easier to use the abovementioned `static` keyword, as well as give you a good indication when it's time to split off some functionality into a seperate file. For a Java programmer, this shouldn't be too strange a practice.

- The standard practices on commenting apply. Use something like Doxygen if you're looking for something similar to javadoc/C# XML comments.

- If you really haven't done anything serious in C for a while, coming to grips with practices for keeping your memory management clean and sensible, even though it's not hard per se, is going to hurt a lot more then establishing practices for maintainability. Just a warning.

Problem

I've been working/coding in C#/Java for some years, so the basics etc. don't give me to much a hard time. But I've never done anything larger than small commandline learning programs in c. Now I'm trying to make a mobile phone emulator for Linux and I have no clue how to structure my code when its not object oriented. I have 3 big books that cover c in detail but none of them cover how to code for maintainability in a bigger project. So i was hoping some of you more experienced people could point me to a best practice or similar?

Original source

Related problems