Date: Thu, 5 Apr 2001 21:10:48 -0700 (PDT) From: Matt Dillon <dillon@earth.backplane.com> To: "T. William Wells" <bill@twwells.com> Cc: freebsd-bugs@freebsd.org Subject: Re: ntpd patch Message-ID: <200104060410.f364AmX37732@earth.backplane.com> References: <E14lLSx-000Ei4-00@twwells.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200104060410.f364AmX37732>
