Return-Path: owner-tiff@olympiakos.com
Return-Path: <owner-tiff@olympiakos.com>
Received: from localhost (localhost [127.0.0.1])
	by at1895.spb.edu (8.12.0.Beta7/8.12.0.Beta7) with ESMTP id f6U8Uo08001701
	for <dron@localhost>; Mon, 30 Jul 2001 13:13:12 +0400
Received: from eudoramail.com [209.185.123.45]
	by localhost with POP3 (fetchmail-5.8.1)
	for dron@localhost (single-drop); Mon, 30 Jul 2001 13:13:12 +0400 (MSD)
Received: from gate7.olympiakos.com ([207.176.88.85]) by shared1-mail.whowhere.com; Fri Jul 27 12:50:04 2001
Received: from localhost (daemon@localhost)
	by gate7.olympiakos.com (8.9.3/8.9.3) with SMTP id PAA10384;
	Fri, 27 Jul 2001 15:36:14 -0400
Received: by gate7.olympiakos.com (bulk_mailer v1.9); Fri, 27 Jul 2001 15:34:16 -0400
Received: (from majordom@localhost)
	by gate7.olympiakos.com (8.9.3/8.9.3) id PAA10196
	for tiff-outgoing; Fri, 27 Jul 2001 15:34:15 -0400
X-Authentication-Warning: gate7.olympiakos.com: majordom set sender to owner-tiff@olympiakos.com using -f
Received: from mailout02.sul.t-online.de (mailout02.sul.t-online.com [194.25.134.17])
	by gate7.olympiakos.com (8.9.3/8.9.3) with ESMTP id PAA10181
	for <tiff@olympiakos.com>; Fri, 27 Jul 2001 15:34:12 -0400
Received: from fwd03.sul.t-online.de 
	by mailout02.sul.t-online.de with smtp 
	id 15QDN7-0004Wd-09; Fri, 27 Jul 2001 21:34:05 +0200
Received: from p3E9E1747.dip.t-dialin.net (027122869-0001@[62.158.23.71]) by fwd03.sul.t-online.com
	with smtp id 15QDMz-0IthOTC; Fri, 27 Jul 2001 21:33:57 +0200
Date: 27 Jul 2001 21:24:35 +0100
From: Andreas_Kleinert@t-online.de (Andreas R. Kleinert)
Subject: Re: Possible bug with SBYTE type
To: "Neil Talsania" <neil.talsania@kodak.com>
In-Reply-To: <003901c0f323$ef9024a0$451f6696@kodak.com>
Message-ID: <1863.608T1768T12843974info@ar-kleinert.de>
MIME-Version: 1.0
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7bit
Cc: tiff@olympiakos.com
X-Mailer: THOR 2.6a (Amiga;TCP/IP)
X-Sender: 027122869-0001@t-dialin.net
Sender: owner-tiff@olympiakos.com
Status: RO
Content-Length: 1838
Lines: 50

>Here is what I am trying to do. I have an image that is of type CHAR, thus the
>range of values are from -128 to +127. I am trying to set the SMIN tag to
>-128, however when I get the value back it is +128.

>So, then I started looking at the code. And I verified with a debugger that
>the value that I am trying to write is -128. The problem seems to be when I
>read it back in. Because the type for the SMIN tag is of type any, and my data
>is CHAR, it is getting written out as a SBYTE type. When this gets read back
>in, the data is promoted to a USHORT in the call to FetchByteArray, then the
>value is casted back to a SHORT, however by this time the sign has been lost,
>and now my -128 (which I believe would be 10000000 in twos complement binary
>representation for a single byte) has become +128 (which for a short would be
>represented by 0000000010000000).

 For the following code my compiler prints "65408" and "-128":

 *************************************************************

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
   signed char  sB;
 unsigned short uW;
   signed short sW;

   sB = -128;
   uW = sB;   printf("unsigned short: %lu\n", uW);
   sW = uW;   printf("signed short:   %ld\n", sW);

  exit(0);
}

 *************************************************************

 If I replace the "sB" declaration by

   unsigned char sB;

 it prints "128" and "128".

 Conclusion: your C compiler's default setting for "CHAR" (char ?)
 is not "signed" but "unsigned". This is ok for the C standard,
 but you may wish to reconfigure your compiler and/or CHAR typedef.

--
Andreas_Kleinert@t-online.de  | http://www.ar-kleinert.de             |
Freelance Consultant & Writer | Software Engineering                  |
 *** PerSuaSiVe SoftWorX ***  | x86 Win/Linux, 68k/PPC Amiga and more |

