Re: [tcpdump-workers] [tcpdump] About HAVE_NO_PRINTF_Z

2023-01-12 Thread Francois-Xavier Le Bail via tcpdump-workers
--- Begin Message ---
On 12/01/2023 10:04, Denis Ovsienko wrote:
> Do you think it would be
> appropriate to use [again] %lu instead of %zu for size_t [...] on systems 
> that don't have %zu [...]?

The problem is that the needed conversion specification is "%lu" on 64 bits 
system and "%u" on 32 bits system.
--- End Message ---
___
tcpdump-workers mailing list
tcpdump-workers@lists.tcpdump.org
https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers


Re: [tcpdump-workers] [tcpdump] About HAVE_NO_PRINTF_Z

2023-01-12 Thread Denis Ovsienko via tcpdump-workers
--- Begin Message ---
On Thu, 12 Jan 2023 00:10:22 -0800
Guy Harris via tcpdump-workers 
wrote:

> So, if we care about %z support:
> 
>   on UN*Xes, we'd have to drop support for OSes that don't
> provide a C library that supports it;

Thank you for the detailed analysis, Guy.  I did not realize the support
is in the libc space rather than C99 space.  Do you think it would be
appropriate to use [again] %lu instead of %zu for size_t and %ld instead
of %z for ssize_t on systems that don't have %zu and %z?

For that the HAVE_NO_PRINTF macro would have to be ported to CMake, but
then the currently conditional tests would be able to pass everywhere
(i.e. on Solaris 9).

Whatever is the eventual solution, in any case from today's perspective
it makes sense to stop masking these test failures.

-- 
Denis Ovsienko
--- End Message ---
___
tcpdump-workers mailing list
tcpdump-workers@lists.tcpdump.org
https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers


Re: [tcpdump-workers] [tcpdump] About HAVE_NO_PRINTF_Z

2023-01-12 Thread Guy Harris via tcpdump-workers
--- Begin Message ---
On Jan 11, 2023, at 11:06 PM, Guy Harris via tcpdump-workers 
 wrote:

> On UN*Xes, the C library is typically the system API library, so it's bundled 
> with the OS rather than the compiler, so I don't know whether this is an 
> issue of Sun C 5.9 or SunOS 5.9 (the core OS part of Solaris 9).

Solaris 9 printf() man page:

https://docs.oracle.com/cd/E19683-01/816-0213/6m6ne387j/index.html

"An optional h specifies that a following d, i, o, u, x, or X conversion 
character applies to a type short int or type unsigned short int argument (the 
argument will be promoted according to the integral promotions, and its value 
converted to type short int or unsigned short int before printing); an optional 
h specifying that a following n conversion character applies to a pointer to a 
type short int argument; an optional l (ell) specifying that a following d, i, 
o, u, x, or X conversion character applies to a type long int or unsigned long 
int argument; an optional l (ell) specifying that a following n conversion 
character applies to a pointer to a type long int argument; an optional ll (ell 
ell) specifying that a following  d, i, o, u, x, or X conversion character 
applies to a type long long or unsigned long long argument; an optional ll (ell 
ell) specifying that a following n conversion character applies to a pointer to 
a long long argument; or an optional L specifying that a following e, E, f, g, 
or G conversion character applies to a type long double argument. If an h, l, 
ll, or L appears with any other conversion character, the behavior is 
undefined."

No mention of z.

Solaris 10 printf() man page:

https://docs.oracle.com/cd/E19253-01/816-5168/6mbb3hrj1/index.html

"Length Modifiers

The length modifiers and their meanings are:

...

z

Specifies that a following d, i, o, u, x, or X conversion 
specifier applies to a size_t or the corresponding signed integer type 
argument; or that a following n conversion specifier applies to a pointer to a 
signed integer type corresponding to size_t argument."

So I suspect it's more like "C on Solaris 9 only supports %z if the compiler 
includes a library with a printf family that supports it and the compiler 
driver causes programs to be linked with that library before -lc; C on Solaris 
10 and later supports %z even if the compiler relies on the system library for 
printf-family functions".

I don't know whether any C99-supporting versions of GCC, when built on Solaris 
9 for Solaris 9, provides their own printf-family functions with %z support.  
The GCC 4.6.4 manual says, in section 2 "Language Standards Supported by GCC":

https://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Standards.html#Standards

in subsection 2.1 "C language":

The ISO C standard defines (in clause 4) two classes of conforming 
implementation. A conforming hosted implementation supports the whole standard 
including all the library facilities; a conforming freestanding implementation 
is only required to provide certain library facilities: those in , 
, , and ; since AMD1, also those in; 
and in C99, also those in  and . In addition, complex 
types, added in C99, are not required for freestanding implementations. The 
standard also defines two environments for programs, a freestanding 
environment, required of all implementations and which may not have library 
facilities beyond those required of freestanding implementations, where the 
handling of program startup and termination are implementation-defined, and a 
hosted environment, which is not required, in which all the library facilities 
are provided and startup is through a function int main (void) or int main 
(int, char *[]). An OS kernel would be a freestanding environment; a program 
using the facilities of an operating system would normally be in a hosted 
implementation.

GCC aims towards being usable as a conforming freestanding 
implementation, or as the compiler for a conforming hosted implementation. By 
default, it will act as the compiler for a hosted implementation, defining 
__STDC_HOSTED__ as 1 and presuming that when the names of ISO C functions are 
used, they have the semantics defined in the standard. To make it act as a 
conforming freestanding implementation for a freestanding environment, use the 
option -ffreestanding; it will then define __STDC_HOSTED__ to 0 and not make 
assumptions about the meanings of function names from the standard library, 
with exceptions noted below. To build an OS kernel, you may well still need to 
make your own arrangements for linking and startup. See Options Controlling C 
Dialect.

GCC does not provide the library facilities required only of hosted 
implementations, nor yet all the facilities required by C99 of freestanding 
implementations; to use the facilities of a hosted environment, you will need 
to find them elsewhere (for example, in the GNU C library). Se