C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Type-safe printf and auto

From: Robin Rowe <robin.rowe_at_[hidden]>
Date: Sun, 12 Mar 2023 14:08:12 -0700
> For printing the value, whatever the type is, you should use "%jd" and
> cast the value to (intmax_t).

Thank you, Alejandro. You are right of course that a cast can silence a
type warning.

Sometimes I do cast the printf arg like you suggest, but to (int), not
bothering with intmax_t. Narrowing legacy code variables that work fine
in 32-bit is unlikely to cause trouble. While I've often done that, and
used stringize macros too as you suggested, I would prefer a general
solution that is elegant.
Appreciate all feedback.

Robin

Received on 2023-03-12 21:08:16