From owner-freebsd-chat Mon Aug 30 2:39:30 1999 Delivered-To: freebsd-chat@freebsd.org Received: from sand2.global.net.uk (sand2.global.net.uk [195.147.246.100]) by hub.freebsd.org (Postfix) with ESMTP id 4F93815108 for ; Mon, 30 Aug 1999 02:39:23 -0700 (PDT) (envelope-from mark@globalnet.co.uk) Received: from p2fs12a06.client.global.net.uk ([195.147.220.48] helo=marder-1.) by sand2.global.net.uk with esmtp (Exim 2.05 #1) id 11LNsk-0006rP-00; Mon, 30 Aug 1999 10:37:43 +0100 Received: (from mark@localhost) by marder-1. (8.9.2/8.8.8) id KAA00529; Mon, 30 Aug 1999 10:29:39 +0100 (BST) (envelope-from mark) Date: Mon, 30 Aug 1999 10:29:39 +0100 From: Mark Ovens To: Ben Smithurst Cc: chat@freebsd.org Subject: Re: Correct casting in ANSI C Message-ID: <19990830102938.A265@marder-1> References: <19990830001201.C265@marder-1> <19990830011750.A37445@lithium.scientia.demon.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.95.3i In-Reply-To: <19990830011750.A37445@lithium.scientia.demon.co.uk>; from Ben Smithurst on Mon, Aug 30, 1999 at 01:17:51AM +0100 Organization: Total lack of Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org On Mon, Aug 30, 1999 at 01:17:51AM +0100, Ben Smithurst wrote: > Mark Ovens wrote: > > > To achieve *strict* ANSI compliance, what is the correct way to > > use cast(s) in the following code. > > > > gcc doesn't complain, even with ``-Wall'', > > Or `-Wall -ansi -pedantic'. > No > > but Sun's ANSI C compiler > > gives a warning like "the semantics of SCONV change in ANSI C; use > > an explicit cast". Do I need to cast each int (& the literal 1000), > > or just cast the whole expression? > > > > int i = 123, j = 57, k = 500; > > double d; > > > > d = i / j + k / 1000; > > Hmm. I think you can just cast one part of each division, to make it do it > in floating point, or something. How about > > d = (double)i / j + (double)k / 1000; > > or, somewhat cleaner, > > d = (double)i / j + k / 1000.0; > Both of these work of course but the second one is, as you say, cleaner. It was just that there was a debate at work about the correct way (someone said you had to cast *all* the ints) to be *strict* ANSI. > Otherwise it will just do an integer division (or so it appears -- I'm > not an expert at this sort of thing). It seems you need to get some > floating point into each division. > That's what I think. > You might like to go and ask this in comp.lang.c, where all the ANSI C > experts hang out. > I may do that. > Incidentally, your mail came through with lines padded out to 80 > characters with trailing spaces, did you break something? I don't think > it's my end, I haven't noticed it on anything else. > Interesting. I made a typo in the address and it bounced so I just copied and pasted the original into a new message. Mutt, it seems, pads the displayed lines to the window width. BTW Ben, I've used the 2 font progs you sent me, fontdump and fontmake. Great job (I wanted to make an iso-8x8 thin font). Only thing that took a while to figure out is that the .fnt files are uuencoded. > -- > Ben Smithurst | PGP: 0x99392F7D > ben@scientia.demon.co.uk | key available from keyservers and > | ben+pgp@scientia.demon.co.uk > -- STATE-OF-THE-ART: Any computer you can't afford. OBSOLETE: Any computer you own. ________________________________________________________________ FreeBSD - The Power To Serve http://www.freebsd.org My Webpage http://ukug.uk.freebsd.org/~mark/ mailto:mark@ukug.uk.freebsd.org http://www.radan.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message