C++ Logo


Advanced search

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

From: Alejandro Colomar (man-pages) <"Alejandro>
Date: Mon, 13 Mar 2023 11:33:16 +0100
On Mon, Mar 13, 2023, 03:02 Robin Rowe via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> > No, that's not silencing a warning. That's fixing the bug. That's one
> > of the few places where a cast is the right thing.
> Interesting idea, Alex. However, I don't think so. Doing a cast is
> always taking a chance of unexpected results. I typically fix printf
> warnings by changing the format to use the right flag.
> Just a thought, if casting to (intmax_t) is always the right thing, then
> printf would only need one integer format flag... ;-)

Sorry, I meant always in the context of variables of a type that doesn't
have already a specifier, like suseconds_t. For variables that have a
type, though, you can use it without a problem.

There's no danger at all introduced by the cast.

In fact, when debugging (adding printfs all around), to go faster, I always
cast everything blindly in the printf calls.

> Appreciate the feedback.
> Robin
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-03-13 10:33:29