[Swan-dev] intmax_t

D. Hugh Redelmeier hugh at mimosa.com
Fri Nov 3 15:50:49 UTC 2017

| From: Andrew Cagney <cagney at vault.libreswan.fi>
| New commits:
| commit 9e5d7a6855f1e89c03537e0a7983fd352190f693
| Author: Andrew Cagney <cagney at gnu.org>
| Date:   Thu Nov 2 13:21:09 2017 -0400
|     timers: use intmax_t for deltamillisecs
|     The signed type is used since deltatime_t can be -ve.  On 32-bit
|     systems, code using long was limited to +-12 days (lucky all timeouts
|     are less than that).
|     Update some obvious printf statements (use %jd) and variables (replace
|     unsigned long with intmax_t).

I'm sorry I didn't mention this earlier.

(I don't remember the details of whether this needs to be signed or
not.  I'll ignore that for now.)

intmax_t is kind of horrible for correctness.  Portable code can have no idea
what range of values that it represent (and no idea how expensive it is
in object code).

Of course the same can be said of int and long.

I recommend type int32_t since:

- we know that it is good enough

- we can check that settings from config files don't violate this

(But C now specifies that int is at least 32 bits wide, so it would be
good enough.  long is allowed to be only 32 bits wide too so it
doesn't really have an advantage over int.)

If int32_t is too limiting, use int64_t.

More information about the Swan-dev mailing list