| | |
Project/File design
Thread Solved
![]() |
I am having some trouble with the layout of my project. I'm using several APIs, including the WinAPI and DevIL. I had hoped to encapsulate each one in a separate header file, so that the main program would never have to know whats going on. The problem is, some functions have to refer to each other in different files. Is there any way I can let them do this and still keep the encapsulation?
I started experimenting with all sorts of bizarre extern statements and separate .c files but I realized it would be a lot easier to require the client (main) to call the subsequent functions, rather than have them call each other. It will require more parameters but it seems to be much better style anyway.
•
•
Join Date: Sep 2008
Posts: 1,514
Reputation:
Solved Threads: 189
It's not necessarily better style/design. And if the job of one function requires another function, then you should call the other function within the first function. You shouldn't use main to do it. And I'm kind of curious how to do this as well, which is why I am upping this topic. Its been a while since I've programmed in C, but I would think you'd just include the one header in the other one. Since you need to compile each file into a .o, I'm not sure where that comes into play though. Guess you'd just always have to link them somehow.
Last edited by BestJewSinceJC; Dec 31st, 2008 at 12:28 pm.
I had a thought, what if you just declared the function you need to reference in the top of the file that uses it? If file header1.h needs function doSomething() which is defined in another header, put
in the top of header1.h
C Syntax (Toggle Plain Text)
void doSomething()
Sorry for all the stupid reposts, but you can only edit for so long. Anyway, I refined my previous idea. Just put all the function definitions in one header file and have all the other headers include it. That way every function knows about every other function.
Last edited by death_oclock; Jan 1st, 2009 at 3:46 am.
•
•
•
•
Just put all the function definitions in one header file and have all the other headers include it. That way every function knows about every other function.
Look at extremelly rational C library headers structure. Group all your global functions, typedefs and global macros by themes. Place related declarations in correspondent .h files. Include only needed .h files in .c modules. Never mix unrelated function definitions in a single .c file.
If the most of your functions use common (as usually system) headers, place correspondent includes in the single common .h file (common.h, for example). Try to use precompiled headers feature of your compiler. For example, in VC++ place all system header include directives in stdafx.h.
Now your include police looks like:
c Syntax (Toggle Plain Text)
/* .c file brief description */ #include "common.h" #include "theme1.h" #include "utility.h" /* theme1 function definitions */
•
•
•
•
I didn't quite understand that. I get the idea of using a common header for system includes. But the rest I wasn't sure of. Am I right in thinking this: include all formal function declarations first, then all their definitions?
![]() |
Similar Threads
- I need a great web designer and proffesional PHP Coder ~ 10k project (Web Development Job Offers)
- Need A Pro Coder Mysql Php Website Designer! Will Pay! For This Project (Web Development Job Offers)
- File Operations (C++)
- Web design & web development (Post your Resume)
- Have a problem with centering "jpg" files (HTML and CSS)
- project on the banking sector using .Net (VB.NET)
- hijackthis log for bridge.dll file missing - yes version 1.99.0 (Viruses, Spyware and other Nasties)
- Database Design Advice (MySQL)
- Help with algorithm design (Java)
Other Threads in the C Forum
- Previous Thread: Windows Registry problem
- Next Thread: Query related to Hiding symbol in Shared Library
| Thread Tools | Search this Thread |
* adobe ansi api array asterisks binarysearch calculate centimeter changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory feet fflush fgets file floatingpointvalidation fork forloop frequency givemetehcodez grade gtkgcurlcompiling gtkwinlinux hacking highest histogram inches input intmain() iso kernel keyboard kilometer km linked linkedlist linux linuxsegmentationfault list locate looping loopinsideloop. lowest match microsoft mqqueue mysql number oddnumber odf opendocumentformat openwebfoundation owf pattern pdf performance posix probleminc process program programming radix recv recvblocked repetition research reversing scanf scheduling segmentationfault sequential single socket socketprograming socketprogramming stack standard string systemcall threads turboc unix urboc user variable voidmain() wab whythiscodecausesegmentationfault windows.h windowsapi






