bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: "Marc Nieper-Wißkirchen" <marc.nieper+gnu@gmail.com>
Cc: bug-gnulib@gnu.org
Subject: Re: stack module
Date: Thu, 23 Jul 2020 12:36:18 +0200	[thread overview]
Message-ID: <11510067.FCFjWOerkP@omega> (raw)
In-Reply-To: <CAEYrNrSy=eZUpBS3D=xUArrVN8JyivyA4crjbSy0bu9RN3kP5w@mail.gmail.com>

Hi Marc,

> The alternative with the same type safety would be a source file with
> stack code procedures meant for inclusion (without include guards).
> The source file would expect a preprocessor defines GL_STACK_NAME,
> GL_STACK_TYPE, and GL_STACK_EXTERN.
> 
> The file itself would contain code like the following:
> 
> #define _GL_STACK_PREFIX(name) _GL_CONCAT(GL_STACK_NAME, _GL_CONCAT(_, name))
> 
> typedef struct
> {
>   GL_STACK_TYPE *base;
>   size_t size;
>   size_t allocated;
> }
> GL_STACK_PREFIX(type);
> 
> GL_STACK_EXTERN GL_STACK_PREFIX(init) (GL_STACK_PREFIX(type) *stack)
> {
>   stack->base = NULL;
>   stack->size = 0;
>   stack->allocated = 0;
> }
> 
> ...
> 
> The advantage of this model is that it generalizes to other data
> structures, for which a sole (or at least simple) macro implementation
> is not possible.

This is perfectly acceptable for Gnulib. It has debuggability and type safety.

You have precedent e.g. in lib/diffseq.h and lib/aligned-malloc.h.

You can even omit the 'GL_' prefix from the macro names. The user can #undef
the macros after including the file; therefore there is nearly no risk of
collision with macros defined by other code.

Bruno



  reply	other threads:[~2020-07-23 10:36 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-28  7:08 Add gl_list_remove_last to list/xlist Marc Nieper-Wißkirchen
2020-05-02  0:07 ` Bruno Haible
2020-05-02  7:16   ` Marc Nieper-Wißkirchen
2020-05-02 12:07     ` Bruno Haible
2020-05-02 12:49       ` Marc Nieper-Wißkirchen
2020-05-02 15:49         ` Bruno Haible
2020-05-02 16:04           ` Marc Nieper-Wißkirchen
2020-05-22 15:59           ` Marc Nieper-Wißkirchen
2020-05-23 12:30             ` stack module Bruno Haible
2020-05-23 12:42               ` Marc Nieper-Wißkirchen
2020-05-23 14:02                 ` Bruno Haible
2020-05-23 14:36                   ` Marc Nieper-Wißkirchen
2020-05-23 15:39                     ` Paul Eggert
2020-05-23 15:55                       ` Marc Nieper-Wißkirchen
2020-05-23 16:44                         ` Paul Eggert
2020-05-23 16:54                           ` Marc Nieper-Wißkirchen
2020-05-23 17:33                             ` Paul Eggert
2020-05-23 17:38                               ` Marc Nieper-Wißkirchen
2020-05-23 20:51                                 ` Paul Eggert
2020-05-23 21:07                                   ` Marc Nieper-Wißkirchen
2020-05-23 22:06                                   ` Bruno Haible
2020-05-24  2:14                                     ` Paul Eggert
2020-05-24  8:17                                       ` Marc Nieper-Wißkirchen
2020-05-24 19:07                                         ` Paul Eggert
2020-05-24 19:26                                           ` Bruno Haible
2020-06-02 13:44                                             ` Marc Nieper-Wißkirchen
2020-05-23 17:19                     ` Bruno Haible
2020-07-22 20:17                       ` Marc Nieper-Wißkirchen
2020-07-23 10:36                         ` Bruno Haible [this message]
2020-07-23 10:56                           ` Marc Nieper-Wißkirchen
2020-10-07  9:01                           ` Marc Nieper-Wißkirchen
2020-10-07 11:31                             ` Marc Nieper-Wißkirchen
2020-10-10 14:06                               ` Bruno Haible
2020-10-10 14:35                                 ` Marc Nieper-Wißkirchen
2020-10-10 15:10                                   ` ChangeLog entries Bruno Haible
2020-05-02 21:24       ` Add gl_list_remove_last to list/xlist Bruno Haible
2020-05-03 11:14         ` Bruno Haible
2020-05-05  8:37         ` Marc Nieper-Wißkirchen
2020-05-08 17:28           ` Bruno Haible
2020-06-03 16:32         ` Marc Nieper-Wißkirchen
2020-06-03 21:08           ` Bruno Haible
2020-06-03 21:22             ` Marc Nieper-Wißkirchen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11510067.FCFjWOerkP@omega \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=marc.nieper+gnu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).