Re: What are __dead2 and __unused in the source code?
- In reply to: Mehdi Khawari : "What are __dead2 and __unused in the source code?"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 21 Nov 2023 15:54:30 UTC
On Tue, 21 Nov 2023 15:12:51 +0100 Mehdi Khawari <iam.mehdikhawari@gmail.com> wrote: > Hi, everyone! > > I'm just learning by studying the source code of some basic tools > included in the base and I had a question. These macros are defined in /usr/include/sys/cdefs.h, they're hints to the compiler to prevent warnings that would otherwise occur and break the build with --Wall which turns all warnings into errors. > Why is __dead2 applied to some function like usage? > static void usage(void) __dead2; __dead2 hints that the function is not expected to return. > What is the reason that __unused is applied to the function argument like > here: __unused lets the compiler know that this parameter is not used intentionally. > static void > siginfo_handler(int sig __unused) > { > siginfo = 1; > } > These snippets are from /bin/chmod/chmod.c. Where can I find more > information on this? In each case without the hint the compiler would throw a warning, which the default --Wall option would turn into an error. There's a NetBSD manpage which covers similar constructs, but there doesn't seem to be a FreeBSD version of it. https://man.netbsd.org/NetBSD-6.1/__dead.3 -- Steve O'Hara-Smith <steve@sohara.org>