All of lore.kernel.org
 help / color / mirror / Atom feed
* clumsy cast in dlopen.3
@ 2026-05-14 10:56 Bruno Haible
  2026-05-14 11:29 ` Alejandro Colomar
  0 siblings, 1 reply; 9+ messages in thread
From: Bruno Haible @ 2026-05-14 10:56 UTC (permalink / raw)
  To: linux-man

The dlopen.3 man page contains this text:

                  *(void **) &cosine = dlsym(handle, "cos");

              This (clumsy) cast conforms with the ISO C standard and will
              avoid any compiler warnings.

However, such a cast violates the strict aliasing rules of ISO C, no?

The proper workaround is to use a union:

  union { double (*cosine) (double); void *pointer; } u;

  u.pointer = dlsym(handle, "cos");
  ...
  printf("%f\n", u.cosine(2.0));

Bruno




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

end of thread, other threads:[~2026-05-15 22:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-14 10:56 clumsy cast in dlopen.3 Bruno Haible
2026-05-14 11:29 ` Alejandro Colomar
2026-05-15  8:35   ` AW: " Walter Harms
2026-05-15  9:56     ` Alejandro Colomar
2026-05-15 14:05       ` Martin Uecker
2026-05-15 15:15         ` Alejandro Colomar
2026-05-15 15:41         ` [PATCH v1] man/man3/dlopen.3: EXAMPLES: Simplify use of dlsym(3) Alejandro Colomar
2026-05-15 16:19           ` Bruno Haible
2026-05-15 22:51             ` Alejandro Colomar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.