Date: Mon, 30 Aug 1999 10:29:39 +0100 From: Mark Ovens <mark@ukug.uk.freebsd.org> To: Ben Smithurst <ben@scientia.demon.co.uk> Cc: chat@freebsd.org Subject: Re: Correct casting in ANSI C Message-ID: <19990830102938.A265@marder-1> In-Reply-To: <19990830011750.A37445@lithium.scientia.demon.co.uk>; from Ben Smithurst on Mon, Aug 30, 1999 at 01:17:51AM %2B0100 References: <19990830001201.C265@marder-1> <19990830011750.A37445@lithium.scientia.demon.co.uk>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990830102938.A265>
