xref: /illumos-gate/usr/src/test/libc-tests/tests/printf-intmax/printf-intmax.c (revision 81e874d2d1a5be29bb118956027e1ea70e79e530)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2025 Hans Rosenfeld
14  */
15 
16 /*
17  * The 32bit libc contains special variants of all printf functions
18  * for a strict C89 environment where intmax_t is only 32 bits wide.
19  * These handle intmax_t arguments ('j' length modifier) accordingly.
20  *
21  * Since our feature-tests header assumes that if __GNUC__ is defined,
22  * then we also always have a long long type, so it is used for intmax_t
23  * when compiling with gcc even with -std=c89 -pedantic. To work around
24  * this, allowing this test to actually do what it needs to do based on
25  * how it is compiled, we undef __GNUC__ here.
26  */
27 
28 #undef __GNUC__
29 
30 #include <stdio.h>
31 
32 int
main(int argc,char ** argv)33 main(int argc, char **argv)
34 {
35 	printf("long long: %#llx\n", (long long)-1);
36 	printf("intmax_t: %#jx\n", (long long)-1);
37 
38 	return (0);
39 }
40