Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: arranging items in a array with a sorted pointer-list Date: Sun, 06 Dec 2020 05:34:07 -0800 Organization: A noiseless patient Spider Lines: 72 Message-ID: <86blf7kqi8.fsf@linuxsc.com> References: <87wny3yp2n.fsf@bsb.me.uk> <20201130124004.239@kylheku.com> <%6dxH.49582$kM7.20584@fx43.iad> <20201130142116.891@kylheku.com> <1by2ii72fj.fsf@pfeifferfamily.net> <814ca073-ab14-42cc-8f14-3571078bb04an@googlegroups.com> <9YsxH.30679$Zh7.26119@fx04.iad> <87blfdxjmf.fsf@bsb.me.uk> <87h7p4w977.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="048215ee9820886844dd3aade67dded3"; logging-data="31388"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eU+T7+5miHvLKnqUKr8fUiKAkKOMaCxQ=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:TFQnTvyHmhHo81+MZxINkJb5LDk= sha1:cNH7dxH0Ithdz1KrQjgSEs+QNAU= Xref: csiph.com comp.lang.c:156973 James Kuyper writes: > On 12/2/20 9:53 AM, Ben Bacarisse wrote: > >> James Kuyper writes: > > ... > >>> I'm pretty tired right now, so maybe I'm missing something >>> obvious. If written in C, how would bsearch() go about returning >>> a void* when it's arguments are const void*, without casting away >>> const somewhere? In English, the possessive form of "it" is spelled "its", with no apostrophe. The word "it's" is a contraction for "it is". >> There are various ways, but as an old-timer, > > I definitely qualify as an old-time; I remember what C was like > before prototypes were added to the language. They were an enormous > improvement. No one is suggesting otherwise. >> I like >> >> void *remove_const(s) void *s; { return s; } >> >> and in bsearch >> >> return remove_const(ptr); > > I definitely don't like leaving out a function prototype, > particularly when the only reason for doing so is to disable > the type checking enabled by the prototype. Here that isn't the only reason for not using a prototype, nor even the most important reason. A key point of not using a prototype is so the call will have defined behavior. However, if someone is determined never to use functions whose declarations lack prototypes, that restriction too can be accommodated: (file dequalify.h) #ifndef HAVE_DEQUALIFY_dot_H #define HAVE_DEQUALIFY_dot_H extern void * dequalify( const volatile void * ); #endif/*HAVE_DEQUALIFY_dot_H*/ (file dequalify.c) #include "dequalify.h" #include static inline void * fixit( void *f( const volatile void * ), ... ){ va_list a; void *pv; va_start( a, f ), pv = va_arg( a, void * ), va_end( a ); return pv; } void * dequalify( const volatile void *x ){ return fixit( dequalify, x ); }