From owner-freebsd-questions@FreeBSD.ORG Thu Jun 23 09:00:51 2005 Return-Path: X-Original-To: questions@freebsd.org Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9658C16A41C for ; Thu, 23 Jun 2005 09:00:51 +0000 (GMT) (envelope-from dmitry.mityugov@gmail.com) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.203]) by mx1.FreeBSD.org (Postfix) with ESMTP id 43A7343D5C for ; Thu, 23 Jun 2005 09:00:51 +0000 (GMT) (envelope-from dmitry.mityugov@gmail.com) Received: by wproxy.gmail.com with SMTP id 69so367010wri for ; Thu, 23 Jun 2005 02:00:50 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ryY0U4HrCruYT6+90oM5Zbksa2rDSwsq1zS6biLnGomdK3Zs/j76abJqDllh6Ya4P2XukpHhaxi6cDlxvDDAhKBolXRHWT03PAjoEsnZ94TGrZ2rg2MT8Sb40ImDbSZuRYnSM7aI96FZ7UGuRnE+eF/hMQwwR8GG4FOzLplC/ss= Received: by 10.54.118.1 with SMTP id q1mr180230wrc; Thu, 23 Jun 2005 02:00:50 -0700 (PDT) Received: by 10.54.56.33 with HTTP; Thu, 23 Jun 2005 02:00:50 -0700 (PDT) Message-ID: Date: Thu, 23 Jun 2005 13:00:50 +0400 From: Dmitry Mityugov To: Olivier Nicole In-Reply-To: <200506230143.j5N1hkWI097845@banyan.cs.ait.ac.th> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <200506220411.j5M4BQ6G087888@banyan.cs.ait.ac.th> <42B91313.9050807@bhi-hamburg.de> <200506230143.j5N1hkWI097845@banyan.cs.ait.ac.th> Cc: questions@freebsd.org Subject: Re: Using regex(3) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Dmitry Mityugov List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2005 09:00:51 -0000 On 6/23/05, Olivier Nicole wrote: > Thanks Titus, >=20 > > no, you're misunderstanding regoff_t or printf. >=20 > I definitely misunderstand printf. Until now I thought that each place > holder (%d) was associated with one variable and if the type > missmatched, the display could be incorrect. Not exactly. Each placeholder like %d is associated with a corresponding number of bytes placed on the stack for values passed to printf(). In addition, many compilers expand values being placed on the stack to the native data boundary. For example, compilers that produce 32-bit code often expand chars and shorts passed to printf() to ints; corresponding placeholders like %c etc know that those 32-bit values are just chars and shorts and treat them accordingly. If you by mistake use %u instead of %c, printf() may print garbage instead of corresponding char value, but subsequent placeholders will still correspond to correct 32-bit portions of the stack. 64-bit values in 32-bit code are different, because they occupy 2 32-bit chunks on the stack, and if you try to deal with them with %d's, without telling printf() that those are in fact 64-bit values with %lld or similar format specifiers, you'll cause subsequent format specifier to access the high-half of the 64-bit value instead of the corresponding value, and so on; from now on, the entire stack during the call to printf() is misaligned, and all subsequent format specifiers will print garbage. This may explain why you're seeing 0's instead of valid output in your program. Hope this helps. > But in that case, printf seems to take 2 successive %d and split the > variable upon them to make it a %lld. >=20 > I am no C guru, but that sound very bad to me. --=20 Dmitry "We live less by imagination than despite it" - Rockwell Kent, "N by E"