[NSWI004] Where to put it?

Petr Tuma petr.tuma at d3s.mff.cuni.cz
Wed Oct 28 15:31:51 CET 2020


Hi,

Lubomir Bulej will have the most authoritative opinion on what is good style :) I would just offer my view:

> 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.)

Not sure if you mean "use constant directly in code" or "define a macro that is a constant and use that in code". If the latter, then go for it :)

What is the reason your team prefers a more generic approach ? Will you use the macro with many different integer types ? (There are not that many there to begin with ...) You should not spend much time on creating generic constructs that will not be used.

>   * 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

There are many good reasons for putting macros in .c file. If it is a local macro that only helps make your code more readable or efficient, and there is no reason it would be used by other source files, then this sounds like a perfectly fine solution to me.

Petr

P.S.: Now I have to hope Vojtech or Lubomir will not want to grade me :-)


More information about the NSWI004 mailing list