From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4780 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: printf issues Date: Fri, 4 Apr 2014 16:15:16 +0200 Message-ID: <20140404141515.GD3034@port70.net> References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1396620935 3467 80.91.229.3 (4 Apr 2014 14:15:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 4 Apr 2014 14:15:35 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4784-gllmg-musl=m.gmane.org@lists.openwall.com Fri Apr 04 16:15:29 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1WW4u0-0004WP-H0 for gllmg-musl@plane.gmane.org; Fri, 04 Apr 2014 16:15:28 +0200 Original-Received: (qmail 27870 invoked by uid 550); 4 Apr 2014 14:15:27 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 27862 invoked from network); 4 Apr 2014 14:15:27 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:4780 Archived-At: * Morten Welinder [2014-04-04 09:32:18 -0400]: > Unrelatedly, from function fmt_fp: > > #define CONCAT2(x,y) x ## y > #define CONCAT(x,y) CONCAT2(x,y) > [...] > long double round = CONCAT(0x1p,LDBL_MANT_DIG); > > That code is cute as a Hello Kitty door knocker, but really? Let's hope nobody > gets the urge to define LDBL_MANT_DIG as 0100 or (80-16) or some such. before you can mock libc code you need to educate yourself LDBL_MANT_DIG is an identifier (macro definition) that is defined by the libc itself (in arch/$ARCH/bits/float.h), not by the application, nor by the compiler the libc can internally rely on a different contract about the identifiers it defines, than application code that has to rely on the external contracts specified by ISO C so outside the implementation you shouldn't use such a code because there is no guarantee how LDBL_MANT_DIG is defined, but internally the libc knows how it defined its symbols and thus the code is perfectly reasonable (this distinction between public interface contracts and implementation internal interface contracts is often misunderstood: so don't copy-paste code between libc and application code without thinking and don't try to reason about APIs/ABIs used inside the libc based on the public specification of those APIs/ABIs)