[dev] [general][discussion] constants: `#define` or `static const`

From: Matthew Parnell <matt_AT_parnmatt.co.uk>
Date: Thu, 12 Oct 2017 15:21:14 +0100

Afternoon suckless community.

It is made clear in the suckless coding style guide when to use
#define and enums; however, it doesn't mention general global

I would search through the mailing list to see if this has been asked
before; but it seems that gmane fails to search.

I'm writing a header file that will contain constants required.
Should I use:

    #define FOO 123.456


    static double const foo = 123.456;

(or `static const double`, for those who prefer the inconsistent const
style; doesn't matter to the question)

There are pros and cons to both; pre-processor could go either way,
"static const" has scope and type safety, etc.

But specifically about the suckless style; I have seen a lot of
`#define`s and a few `static const` in suckless code.

What is more in line with the suckless style, and why?


Matthew Parnell
Received on Thu Oct 12 2017 - 16:21:14 CEST

This archive was generated by hypermail 2.3.0 : Thu Oct 12 2017 - 16:24:15 CEST