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