Subject: Re: Bug in regex library?
To: None <current-users@NetBSD.ORG>
From: Mike Long <mike.long@analog.com>
List: current-users
Date: 10/29/1996 12:12:36
>Date: Tue, 29 Oct 1996 11:37:56 -0500
>From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>

>And when I make those three lines read
>
>   printf ( "%ld %ld\n" , (long int)pmatch[0].rm_so , (long int)pmatch[0].rm_eo ) ;
>   printf ( "%ld %ld\n" , (long int)pmatch[1].rm_so , (long int)pmatch[1].rm_eo ) ;
>   printf ( "%ld %ld\n" , (long int)pmatch[2].rm_so , (long int)pmatch[2].rm_eo ) ;
>
>then not only does -Wformat shut up, but I also get the expected values
>printed out.

>You made an invalid assumption about regoff_t - namely, that it's
>printf-compatible with "long int" - and got burned by it.  That's all.

<sermon>
Usually, I cast system-defined types to the type *printf() expects, as
der Mouse does above, to prevent exactly this problem.  If you want
your code to be portable, casting arguments to varargs/stdargs
functions is a necessary precaution.
</sermon>
-- 
Mike Long <mike.long@analog.com>     <URL:http://www.shore.net/~mikel>
VLSI Design Engineer         finger mikel@shore.net for PGP public key
Analog Devices, CPD Division          CCBF225E7D3F7ECB2C8F7ABB15D9BE7B
Norwood, MA 02062 USA       (eq (opinion 'ADI) (opinion 'mike)) -> nil