public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
* lfind(3) $3 type should be const
@ 2024-11-14 14:38 Alejandro Colomar
  2024-11-14 16:24 ` Gabriel Ravier
  0 siblings, 1 reply; 3+ messages in thread
From: Alejandro Colomar @ 2024-11-14 14:38 UTC (permalink / raw)
  To: libc-alpha; +Cc: linux-man

[-- Attachment #1: Type: text/plain, Size: 416 bytes --]

Hi!

lfind(3) does not modify its third argument, *nmemb.

It's already suspicious that it takes a pointer, but I guess it's due to
historic reasons, and that's already set in stone.

However, I don't see why we should not make it 'const'.  The function
doesn't use it as an output pointer.  Should I sent a patch for
constifying it?

Have a lovely day!
Alex

-- 
<https://www.alejandro-colomar.es/>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: lfind(3) $3 type should be const
  2024-11-14 14:38 lfind(3) $3 type should be const Alejandro Colomar
@ 2024-11-14 16:24 ` Gabriel Ravier
  2024-11-14 16:36   ` Alejandro Colomar
  0 siblings, 1 reply; 3+ messages in thread
From: Gabriel Ravier @ 2024-11-14 16:24 UTC (permalink / raw)
  To: Alejandro Colomar, libc-alpha; +Cc: linux-man

On 11/14/24 3:38 PM, Alejandro Colomar wrote:
> Hi!
>
> lfind(3) does not modify its third argument, *nmemb.
>
> It's already suspicious that it takes a pointer, but I guess it's due to
> historic reasons, and that's already set in stone.
>
> However, I don't see why we should not make it 'const'.  The function
> doesn't use it as an output pointer.  Should I sent a patch for
> constifying it?


I believe the reason is that it aims to mirror lsearch, and to be able 
to be used with it interchangeably as a function with the same type - 
doesn't `const` make the pointer types distinct and incompatible ?

I'd imagine it's not even used much at all elsewhere given how simple it 
is and how cumbersome it is to use compared to an directly inlined 
implementation. That is, I think making it non-const might just happen 
to break a majority of uses of it.

The only way to plausibly rectify this, I think, would be to make the 
compatibility implicit in the standard for any similar function (in the 
same way one might like to make it standard to e.g. pass a pointer to a 
pointer to const char to strtol).


>
> Have a lovely day!
> Alex
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: lfind(3) $3 type should be const
  2024-11-14 16:24 ` Gabriel Ravier
@ 2024-11-14 16:36   ` Alejandro Colomar
  0 siblings, 0 replies; 3+ messages in thread
From: Alejandro Colomar @ 2024-11-14 16:36 UTC (permalink / raw)
  To: Gabriel Ravier; +Cc: libc-alpha, linux-man

[-- Attachment #1: Type: text/plain, Size: 1353 bytes --]

Hi Gabriel,

On Thu, Nov 14, 2024 at 05:24:36PM GMT, Gabriel Ravier wrote:
> On 11/14/24 3:38 PM, Alejandro Colomar wrote:
> > Hi!
> > 
> > lfind(3) does not modify its third argument, *nmemb.
> > 
> > It's already suspicious that it takes a pointer, but I guess it's due to
> > historic reasons, and that's already set in stone.
> > 
> > However, I don't see why we should not make it 'const'.  The function
> > doesn't use it as an output pointer.  Should I sent a patch for
> > constifying it?
> 
> 
> I believe the reason is that it aims to mirror lsearch, and to be able to be
> used with it interchangeably as a function with the same type - doesn't
> `const` make the pointer types distinct and incompatible ?

Hmmm.  That makes sense.

Thanks!
Alex

> 
> I'd imagine it's not even used much at all elsewhere given how simple it is
> and how cumbersome it is to use compared to an directly inlined
> implementation. That is, I think making it non-const might just happen to
> break a majority of uses of it.
> 
> The only way to plausibly rectify this, I think, would be to make the
> compatibility implicit in the standard for any similar function (in the same
> way one might like to make it standard to e.g. pass a pointer to a pointer
> to const char to strtol).

-- 
<https://www.alejandro-colomar.es/>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-11-14 16:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-14 14:38 lfind(3) $3 type should be const Alejandro Colomar
2024-11-14 16:24 ` Gabriel Ravier
2024-11-14 16:36   ` Alejandro Colomar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox