bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: "Marc Nieper-Wißkirchen" <marc.nieper+gnu@gmail.com>
Cc: Gnulib bugs <bug-gnulib@gnu.org>
Subject: Re: Type-safe typecasts
Date: Tue, 6 Apr 2021 11:59:57 -0700	[thread overview]
Message-ID: <84aa607b-197b-6e15-ff1d-3bf4a078075c@cs.ucla.edu> (raw)
In-Reply-To: <CAEYrNrQpCuAMpPaTMGX8UK5G0JuR-fuTpv8kiyrdNkQ9BXCqVQ@mail.gmail.com>

On 4/6/21 12:18 AM, Marc Nieper-Wißkirchen wrote:
> So what I have in mind are macros that do a type conversion from A to B and
> that signal an error on modern compilers if the input is not of type A. For
> this, the C11 construct _Generic can be used.

Not sure it's worth the aggravation. Most of the time, the type you're 
converting to void * is obvious from context. (However, I guess I 
wouldn't object in code that I don't have to look at myself. :-)

By the way, the snippet you gave is not portable C code, as it assumes 
that 'void *' and 'struct foo *' have the same machine representation. 
This is not necessarily true on (admittedly now-rare) machines that have 
different flavors of pointers. I suspect the main problem here is either 
in the calling code, or in the API for gl_list_iterator_next: if it 
returned a possibly-null value of type 'const void *' instead of storing 
the result through a 'const void **' pointer, the calling code wouldn't 
have gotten into this portability mess.


  reply	other threads:[~2021-04-06 19:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06  7:18 Type-safe typecasts Marc Nieper-Wißkirchen
2021-04-06 18:59 ` Paul Eggert [this message]
2021-04-06 19:13   ` Marc Nieper-Wißkirchen
2021-04-06 19:20     ` Paul Eggert
2021-04-06 19:34       ` Marc Nieper-Wißkirchen
2021-04-06 20:28       ` gl_list API Bruno Haible
2021-04-06 20:39         ` Paul Eggert
2021-04-06 21:04           ` Bruno Haible
2021-04-06 21:09             ` Marc Nieper-Wißkirchen
2021-04-06 23:03         ` cast macros Bruno Haible
2021-04-18 19:08           ` Ben Pfaff
2021-04-18 19:27         ` gl_list API Ben Pfaff
2021-04-06 20:13     ` Type-safe typecasts Bruno Haible
2021-04-06 19:25 ` Ben Pfaff
2021-04-06 19:54   ` Bruno Haible
2021-04-06 19:56   ` Bruno Haible

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=84aa607b-197b-6e15-ff1d-3bf4a078075c@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --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).