bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Callbacks in the abstact data types and extra contextual data


From: Bruno Haible
Subject: Re: Callbacks in the abstact data types and extra contextual data
Date: Thu, 09 Jul 2020 22:16:09 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-179-generic; KDE/5.18.0; x86_64; ; )

Hi Marc,

> a number of modules (like the hash module or the list module) allow
> the user to specify callbacks (e.g. a comparison function).
> Unfortunately, these procedures do not take a context parameter, which
> can be a problem because C lacks closures.

Is this a practical, actual problem, or only a theoretical one?

I would hesitate to change (or duplicate) public API, when there is no
practical need.

Note that the lack of context can be remedied by
  - use of per-thread variables, or
  - use of nested functions [1], or
  - storing a pointer to the necessary context in the list elements.

> The original qsort function in stdlib.h has the same problem. Glibs
> has remedied the problem by introducing qsort_r.

qsort_r is only portable to glibc systems, FreeBSD, and macOS. And yet,
no one has requested a substitute for it in gnulib. IMO this indicates
that few programs need this function.

Bruno

[1] https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Nested-Functions.html




reply via email to

[Prev in Thread] Current Thread [Next in Thread]