On Mon, 22 Aug 2022 11:15:19 +0100 Chris Down <[email protected]> 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
