diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 19:43:11 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 19:43:11 +0000 |
commit | fc22b3d6507c6745911b9dfcc68f1e665ae13dbc (patch) | |
tree | ce1e3bce06471410239a6f41282e328770aa404a /upstream/debian-bookworm/man3/_Generic.3 | |
parent | Initial commit. (diff) | |
download | manpages-l10n-fc22b3d6507c6745911b9dfcc68f1e665ae13dbc.tar.xz manpages-l10n-fc22b3d6507c6745911b9dfcc68f1e665ae13dbc.zip |
Adding upstream version 4.22.0.upstream/4.22.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'upstream/debian-bookworm/man3/_Generic.3')
-rw-r--r-- | upstream/debian-bookworm/man3/_Generic.3 | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/upstream/debian-bookworm/man3/_Generic.3 b/upstream/debian-bookworm/man3/_Generic.3 new file mode 100644 index 00000000..14e21d46 --- /dev/null +++ b/upstream/debian-bookworm/man3/_Generic.3 @@ -0,0 +1,62 @@ +.\" Copyright (C) 2022 Alejandro Colomar <alx@kernel.org> +.\" +.\" SPDX-License-Identifier: Linux-man-pages-copyleft +.\" +.TH _Generic 3 2023-02-12 "Linux man-pages 6.03" +.SH NAME +_Generic \- type-generic selection +.SH SYNOPSIS +.nf +.BR _Generic( \fIexpression\fP ", type1: " e1 ", " "... /*" \ +", default: " "e */" ); +.fi +.SH DESCRIPTION +.BR _Generic () +evaluates the path of code under the type selector +that is compatible with the type of the controlling +.IR expression , +or +.B default: +if no type is compatible. +.PP +.I expression +is not evaluated. +.PP +This is especially useful for writing type-generic macros, +that will behave differently depending on the type of the argument. +.SH STANDARDS +C11 and later. +.SH EXAMPLES +The following program demonstrates how to write +a replacement for the standard +.BR imaxabs (3) +function, which being a function can't really provide what it promises: +seamlessly upgrading to the widest available type. +.IP +.\" SRC BEGIN (_Generic.c) +.EX +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> + +#define my_imaxabs _Generic(INTMAX_C(0), \e + long: labs, \e + long long: llabs \e + /* long long long: lllabs */ \e +) + +int +main(void) +{ + off_t a; + + a = \-42; + printf("imaxabs(%jd) == %jd\en", (intmax_t) a, my_imaxabs(a)); + printf("&imaxabs == %p\en", &my_imaxabs); + printf("&labs == %p\en", &labs); + printf("&llabs == %p\en", &llabs); + + exit(EXIT_SUCCESS); +} +.EE +.\" SRC END |