[NSWI004] Where to put it?

Sebastian Uhlík uhliksebastian at gmail.com
Wed Oct 28 12:45:08 CET 2020


Hello,

I have a question about a code composition. I want to implement a macro
computing maximal
amount of hexadecimal digits one can use to house an integer. (I would've
been fine with just
using a constant but my team prefers a more generic approach to this
matter.)

The thing is, I don't know where I should put this macro for it to make
most sense. I see these
possibilities but am not sure what is the 'best one' regarding a good
cstyle.


   - lib/printk.h - since this computation is used for printing integers,
   it would make sense
   to put it here, but my teammate pointed out that then the macro would be
   available from
   everywhere lib/printk.h is included (which will be probably everywhere)
   - printk.c - I could put it directly in the .c file since is supposed to
   be used only in it, but
   it seems awkward to me put macro in .c file
   - lib/utils.h - standalone header file for any constants, macros and
   stuff we might want to
   implement (this seem like a good approach to me personally), but it
   comes with
   the same problem as first point does, every macro / util would be
   visible in files that
   are not meant to use it or see it
       e.g. ```#define LOWER_CASE 'a' - 10 ``` which is a constant used for
   printing
       hexadecimal literals 'shouldn't' be visible to a heap operating
   code, should it?

Perhaps I am chasing a ghost thinking like this (I would say
object-oriented?) in a language
like C is. On the other hand, in a review of my code, it was recommended to
me using a `static`
modifier for functions only used for printing (e.g. print_string,
print_pointer, etc.) so the
question might not be completely off.

Best regards,
Sebastian Uhlík
========================================================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://d3s.mff.cuni.cz/pipermail/nswi004/attachments/20201028/863e342e/attachment.htm>


More information about the NSWI004 mailing list