From owner-freebsd-bugs Thu Apr 5 21:11:26 2001 Delivered-To: freebsd-bugs@freebsd.org Received: from earth.backplane.com (earth-nat-cw.backplane.com [208.161.114.67]) by hub.freebsd.org (Postfix) with ESMTP id A400437B440 for ; Thu, 5 Apr 2001 21:11:24 -0700 (PDT) (envelope-from dillon@earth.backplane.com) Received: (from dillon@localhost) by earth.backplane.com (8.11.2/8.9.3) id f364AmX37732; Thu, 5 Apr 2001 21:10:48 -0700 (PDT) (envelope-from dillon) Date: Thu, 5 Apr 2001 21:10:48 -0700 (PDT) From: Matt Dillon Message-Id: <200104060410.f364AmX37732@earth.backplane.com> To: "T. William Wells" Cc: freebsd-bugs@freebsd.org Subject: Re: ntpd patch References: Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org Ummm.. I think both ways are 'correct'. First of all, there is nothing wrong type-casting a signed char into an unsigned char. I really doubt any FreeBSD utility would actually run on a 1's complement machine anyway, so there is no particular reason to try to support it, and gcc will have no problem optimizing (unsigned char)*ptr verses *(unsigned char *)ptr... in fact, there is a very good chance that both would produce exactly the same code as a result, even without using any optimization flags. Casts are one of the easiest optimizations a C compiler can make. -Matt :The correct code for dealing with a plain char pointer is: : : isspace(*(unsigned char *)ptr); : :1) Though the defined type may, in fact, be a character, we are : treating it as an unsigned character and this code makes that : explicit. : :2) This code works on ones complement machines; (unsigned : char)*ptr does not. : :3) This code has a better chance of generating decent code when : optimization is turned off. (unsigned char)*ptr has an implicit : conversion to int, then the explicit conversion to unsigned : char, followed by an implicit conversion to unsigned int. : *(unsigned char *)ptr has only the implicit conversion to an : unsigned int. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message