Subject: printf(3) bug with %ld and %d?
To: None <>
From: None <>
List: tech-userlevel
Date: 10/30/2006 05:37:12

This is weird and perhaps I'm missing something obvious, but if one
invokes printf(3) with an int first, and a long after, result is
OK. But if one switches (long before, int after) -> nonsense.

I'm on:

$ uname -srm
NetBSD 3.0 i386

Test program:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

main(int argc, char **argv)
	int n;
	off_t offset;

	n = 4;
	offset = (off_t) 123456789;

	printf("integer before (%d), long after (%ld)\n", n, offset);
	printf("Long before (%ld), integer after (%d)\n", offset, n);

	exit(EXIT_SUCCESS); /* Success? */
$ gcc -o test_printf test_printf.c
$ test_printf
integer before (4), long after (123456789)
Long before (123456789), integer after (0)

??? What am I missing?
Thierry Laronde (Alceste) <tlaronde +AT+ polynum +dot+ com>
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C