On Jul 16, 2012, at 7:40 AM, Ksenija Slivko wrote:

> Also I have a question about headers. I've read about their order in HACKING 
> file. But, for example, I have umod.c which has "include util.h" and util.h 
> has "include bu.h", "include bn.h" etc. So can I NOT include bn.h, bu.h etc 
> in umod.c, if they've already been in util.h?

You can and usually should still include the headers even if another header 
you're including also includes them.  You could leave them off in the dubious 
name of performance, but the general best practice is to have each source file 
list the header(s) containing the declarations that it actually directly calls. 
 So if you had a file like umod.c make calls to your utility function and libbu 
for printing, for example, it should include util.h and bn.h; however, the only 
files including bn.h should be the ones directly called some bn_*() function.

When you have an *interface* header (e.g., util.h), the situation is similar -- 
the header should only be including the headers necessary in order to properly 
declare the interface and define all types.  The headers needed for the 
implementation still should only be in the util.c implementation file.  The 
util.c file just wouldn't need to include any of the implementation headers 
that were provided by the interface header (util.h) since it is that file's 
interface.
 
> Where shall I put the common code for such situations? For example, there're 
> lots of duplications and copy-pastes from src/libged to src/mged. So Shall I 
> create a new library or to leave the common code in one of these?

There is NO single answer for where to put common code.  They have to be 
considered on a case-by-case basis per refactoring.  For the case of code 
duplicated across libged and mged, you most definitely should not be creating a 
new library (I don't think that's the answer for any of your refactoring).  The 
code was migrated to libged in order to be made more reusable, but then mged 
hasn't been updated to use libged for all of those functions for a whole 
variety of reasons.  If it's not clear to you how to refactor them yet, just 
leave them alone and move on to others that are obvious.

Cheers!
Sean


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
BRL-CAD Developer mailing list
brlcad-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-devel

Reply via email to