summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2023-02-12 20:32:41 +0100
committerAlejandro Colomar <alx@kernel.org>2023-02-12 20:32:42 +0100
commit5cb85d44934c92e5fc0b928f3627bed6f285793d (patch)
treef07c20d2cd2a576e2cc389d2d84500564615a66a
parent629aeb166631adbcba01f88ad563e842f046954d (diff)
_Generic.3: Remove example code
Casting sockaddr structures is just a symptom that these APIs were seriously misdesigned. In GNU C, there's already a better way to handle this (see [[gnu::transparent_union]]). ISO C should be fixed. Let's not promote this kind of code. Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--man3/_Generic.389
1 files changed, 0 insertions, 89 deletions
diff --git a/man3/_Generic.3 b/man3/_Generic.3
index 6ff5e24ea..db1620f5f 100644
--- a/man3/_Generic.3
+++ b/man3/_Generic.3
@@ -27,95 +27,6 @@ that will behave differently depending on the type of the argument.
.SH STANDARDS
C11 and later.
.SH EXAMPLES
-The following code demonstrates how to write
-a macro similar to C++'s
-.BR \%static_cast (),
-which will allow casting safely between a limited set of types.
-It is useful for example when calling
-system calls or library functions that use compatible structures,
-like for example
-.BR bind (2)
-with
-.BR \%sockaddr (3type).
-.IP
-.EX
-/* This code is in the public domain. */
-
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-
-#define sockaddr_cast(t, p) \e
- _Generic(&*(p), \e
- struct sockaddr *: \e
- _Generic((typeof_unqual(t)) NULL, \e
- struct sockaddr_in *: (t) (p), \e
- struct sockaddr_in6 *: (t) (p), \e
- struct sockaddr_un *: (t) (p), \e
- default: (p)), \e
- struct sockaddr **: \e
- _Generic((typeof_unqual(t)) NULL, \e
- struct sockaddr_in **: (t) (p), \e
- struct sockaddr_in6 **: (t) (p), \e
- struct sockaddr_un **: (t) (p), \e
- default: (p)), \e
- const struct sockaddr *: \e
- _Generic((t) NULL, \e
- const struct sockaddr_in *: (t) (p), \e
- const struct sockaddr_in6 *: (t) (p), \e
- const struct sockaddr_un *: (t) (p), \e
- default: (p)), \e
- \e
- struct sockaddr_in *: \e
- _Generic((typeof_unqual(t)) NULL, \e
- struct sockaddr *: (t) (p), \e
- default: (p)), \e
- struct sockaddr_in **: \e
- _Generic((typeof_unqual(t)) NULL, \e
- struct sockaddr **: (t) (p), \e
- default: (p)), \e
- const struct sockaddr_in *: \e
- _Generic((t) NULL, \e
- const struct sockaddr *: (t) (p), \e
- default: (p)), \e
- \e
- struct sockaddr_in6 *: \e
- _Generic((typeof_unqual(t)) NULL, \e
- struct sockaddr *: (t) (p), \e
- default: (p)), \e
- struct sockaddr_in6 **: \e
- _Generic((typeof_unqual(t)) NULL, \e
- struct sockaddr **: (t) (p), \e
- default: (p)), \e
- const struct sockaddr_in6 *: \e
- _Generic((t) NULL, \e
- const struct sockaddr *: (t) (p), \e
- default: (p)), \e
- \e
- struct sockaddr_un *: \e
- _Generic((typeof_unqual(t)) NULL, \e
- struct sockaddr *: (t) (p), \e
- default: (p)), \e
- struct sockaddr_un **: \e
- _Generic((typeof_unqual(t)) NULL, \e
- struct sockaddr **: (t) (p), \e
- default: (p)), \e
- const struct sockaddr_un *: \e
- _Generic((t) NULL, \e
- const struct sockaddr *: (t) (p), \e
- default: (p)), \e
- \e
- default: \e
- (p) \e
- )
-
-socklen_t slen;
-struct sockaddr_un sun;
-
-slen = sizeof(ss);
-getsockname(sfd, sockaddr_cast(struct sockaddr *, &sun), &slen);
-.EE
-.PP
The following program demonstrates how to write
a replacement for the standard
.BR imaxabs (3)