Re: [hackers] [dwm][PATCH RESEND 0/2] Const-correctness fixes

From: Laslo Hunhold <dev_AT_frign.de>
Date: Mon, 22 Aug 2022 12:35:02 +0200

On Mon, 22 Aug 2022 11:15:19 +0100
Chris Down <chris_AT_chrisdown.name> wrote:

Dear Chris,

> Hmm? For example, for the FC/Xft types, fontname is declared as const
> by xfont_create, but then we cast away its constness when passing it
> to FCNameParse. The same goes for text, which we claim is const in
> the drw_font_getexts signature, but then we remove its constness.
>
> In general the existing code seems confused, no? Either we shouldn't
> pass them in as const in the first place, or we should maintain the
> constness that we declare in the function parameters.
>
> There shouldn't be any logical change here, but it seems weird to say
> things are not mutable up front and then waver about it later. Right
> now there's no UB, but making sure we don't cast away the const
> mitigates the risk altogether.

I agree here. Not only should const be used to at least have a partial
"contract" for the function parameters (C doesn't offer a lot in this
regard and it's an easy way to prevent problems), it also allows the
compiler to optimize the code better.

With best regards

Laslo
Received on Mon Aug 22 2022 - 12:35:02 CEST

This archive was generated by hypermail 2.3.0 : Mon Aug 22 2022 - 12:36:38 CEST