[Coco] Card game skeleton for development with CMOC compiler

tim franklinlabs.com tim at franklinlabs.com
Thu Aug 13 08:08:45 EDT 2015


   I agree with Mark. The functions that are in the header file (.h)
   should be moved to the code file (.c). I occasionally put single line
   code in the headers such as:

   int GetValueTimesTen (int value) { return value * 10; }

   As long as the header is not used in any other module OR in the case of
   C++, isolated within a specific namespace, this is OK to do.

   However,

   It's not good practice putting entire functions in the header. Headers
   are for variable definitions, function declarations etc. When creating
   a project with hundreds of source modules, these files mostly will
   require "knowledge" of functions and variables in other code modules.
   This knowledge is passed using the header files. Using your method, the
   functions located in the header files would generate multiple instances
   of the same function. The linker would fault out due to the multiple
   instances.

   Pilot

     On August 13, 2015 at 12:43 AM Mark McDougall
     <msmcdoug at iinet.net.au> wrote:
     On 13/08/2015 1:19 PM, Pierre Sarrazin wrote:
     > Comments and questions are welcome, here or in private.
     It's considered bad practice to put code in headers, unless it's to
     be
     compiled inline.
     Though I also notice CMOC lacks support for "separate compilation",
     and
     suspect this si the reason it is done in this case.
     Perhaps you could move the code and local variables & preprocessor
     directives etc into a .c file and (gasp) #include that in the main
     skeleton file? At least it will be 'nicer' on more complete
     compilers or
     perhaps one day if/when CMOC gets enhanced? Or not.
     Regards,
     --
     | Mark McDougall | "Electrical Engineers do it
     | <http://members.iinet.net.au/~msmcdoug> | with less resistance!"
     --
     Coco mailing list
     Coco at maltedmedia.com
     https://pairlist5.pair.net/mailman/listinfo/coco
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tim at franklinlabs.com.vcf
Type: text/vcard
Size: 245 bytes
Desc: not available
URL: <https://pairlist5.pair.net/pipermail/coco/attachments/20150813/9ac5e007/attachment.bin>


More information about the Coco mailing list