× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: Subject: RE: unsigned char (was Examples)
  • From: "Bob Crothers" <bob@xxxxxxxxxxxxxx>
  • Date: Fri, 16 Jun 2000 18:16:03 -0500
  • Importance: Normal

Barbara,

Just checked the manuals and yes, you are right.  With ILE/C, char defaults
to "unsigned char".  However, I also checked the manual for MSVC and there
char defaults to "signed char".  I am not sure what ANSI C says.

So there are really 2 issues.  Portability and habit.  And I would say for
both, you should use unsigned char for binary data.  This way you do not
have to stop and think which one to use.  I don't know about you, but when I
have to stop and think about things like this, I get it wrong.  I think the
unsigned char is a good habit.  Just like setting them to NULL.

And actually, it is not so much portability of the code, but portability of
the programmer and his/her habits.

Regarding your comment on "if you know it is a structure, just use that".
If there are only a single structure type (single or multiple), then this
will work and is how I'd do it myself.  It is when there is a mixture of
data types (fairly common) that I'd use the unsigned char.

Bob

-----Original Message-----
From: owner-c400-l@midrange.com [mailto:owner-c400-l@midrange.com]On Behalf
Of bmorris@ca.ibm.com
Sent: Friday, June 16, 2000 4:37 PM
To: C400-L@midrange.com
Subject: Subject: RE: unsigned char (was Examples)



>Date: Tue, 13 Jun 2000 15:23:22 -0500
>From: "Bob Crothers" <bob@cstoneindy.com>
>
>Greg,
> ...
>First, I'd recommend you use the following declaration for your space
>pointer:
>
>unsigned char *mySpacePtr;
> ...

This is interesting.  Greg, "char" is normally already an unsigned char.
If it was always true instead of just "normally" I'd say that Bob was
wrong advising you to add "unsigned" to your declaration.  But there
is a possibility of having chars default to signed by coding
  #pragma chars(unsigned)
before any other statements in the file (including directives, so
don't worry about having an include file do this pragma).

That pragma must exist because some implementations of C default char
to signed, so for portable code, I guess you should indeed specify
unsigned for bit-twiddling purposes.  (Not sure how portable your
API/user-space code needs to be though ...)

Greg, if the user-space is known to contain a particular structure, say
the return value from an API, you might as well just declare the pointer
as a pointer to that structure:

  Qus_Generic_Header_0100_t *pGenericHeader;
  QUSPTRUS (myuserspace, &pGenericHeader, &errCode);

Barbara Morris




+---
| This is the C/400 Mailing List!
| To submit a new message, send your mail to C400-L@midrange.com.
| To subscribe to this list send email to C400-L-SUB@midrange.com.
| To unsubscribe from this list send email to C400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: bob@cstoneindy.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.