organizing my code....?

Started by
5 comments, last by ELS1 22 years, 3 months ago
im making a header file that will contain around 50 functions..ive written around 5 so far and they look SLOPPY! void blah(char* string) { //stuff } void close32bitwindow(HWND window) { //stuff } and so on and so on...i was wondering if there is a nicer way of organizing code than this? there are some recursive TONS of recursive functions here also. im new in c...ive been using vb and such...just want some tips and the such how to organize and optimize my code...thanks a lot!
Advertisement
Make them inline if they are small functions.

What you have there is about the neatest it gets.

------------------------------
Simple DirectMedia Layer:
Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net''s Tutorials - (Here)
------------------------------Put THAT in your smoke and pipe it
Organize? Picking a consistent naming style and parameter order is about as good as it gets. Optimize? Inline small functions (as was said) and avoid recursion as much as possible .

[Resist Windows XP''s Invasive Production Activation Technology!]
Do you write the fuction body in the header file? That´s not how you are supposed to do it. Also organize your fuctions in classes with many diffrent cpp and header files. And if a class grow to big (more then 3000 lines) split it up in 2 cpp files and 1 header file (or separate the class into several smaller more specialized classes).

hny,



Zeblar Nagrim, Lord of Chaos
quote:Original post by Zeblar Nagrim
Do you write the fuction body in the header file? That´s not how you are supposed to do it. Also organize your fuctions in classes with many diffrent cpp and header files. And if a class grow to big (more then 3000 lines) split it up in 2 cpp files and 1 header file (or separate the class into several smaller more specialized classes).

hny,



Zeblar Nagrim, Lord of Chaos


so its better to include all the function prototypes in the header file and the function body in a separate .c file? i just found a great c tutorial and am trying to follow the rules correctly.
so its better to include all the function prototypes in the header file and the function body in a separate .c file? i just found a great c tutorial and am trying to follow the rules correctly.
quote:Original post by ELS1
so its better to include all the function prototypes in the header file and the function body in a separate .c file?

Yes, that''s better. If you include a header with full (non-static and non-inline) functions in more than one source file your compiler will complain. So, basically, just put an extern prototype in the header.

[Resist Windows XP''s Invasive Production Activation Technology!]

This topic is closed to new replies.

Advertisement