pointer of 'unsigned char' == 'char'!?

pointer of 'unsigned char' == 'char'!?

Post by 54401-93 Chan Kwong K » Tue, 03 Sep 1996 04:00:00



Is the pointer of 'unsighed char' == the pointer of 'char'!?

--
---
Bestregards
Louis Chan

   /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  /_/  Louis Chan, Kwong Kit                                      /_/_
 /_/_/ Computer Studies, Year 4                                  /_/_/
  /_/  City Univerity of Hong Kong.                               /_/
 /_/                                                             /_/
  /_/                        http://www.cs.cityu.edu.hk/~ckkchan  /_/

  /_/                      pager : +(852)7111 1076 a/c 4624       /_/
 /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
                                            Printed on Recycled Paper.

 
 
 

pointer of 'unsigned char' == 'char'!?

Post by Albert L » Wed, 04 Sep 1996 04:00:00



Quote:

> Is the pointer of 'unsighed char' == the pointer of 'char'!?

> --
> ---
> Bestregards
> Louis Chan

if you have the following:

unsigned char   *uchrPtr;
signed char     *chrPtr;

Then `*uchrPtr` (ie. contents of what `uchrPtr` is pointing to) can
range in values from -127 to +127 (decimal)
and `*chrPtr` (ie. contents of what `chrPtr` is pointing to) can range
in values from 0 to 255 (decimal).

The pointer `uchrPtr` can point to any valid memory location, and
the pointer `chrPtr` can point to any valid memory location.

Hope this helps

 
 
 

pointer of 'unsigned char' == 'char'!?

Post by Lawrence Kirb » Wed, 04 Sep 1996 04:00:00




Quote:>Is the pointer of 'unsighed char' == the pointer of 'char'!?

A pointer to char isn't directly compatible with a pointer to unsigned
char in that you can't directly assign one to the other. Casting between
these types (especially to pointer to unsigned char) is one of the more
benign pointer casts. However if you can avoid doing any pointer casts.
Perhaps if you post more details about what you want to do somebody
might come up with a better approach.

--
-----------------------------------------


-----------------------------------------

 
 
 

pointer of 'unsigned char' == 'char'!?

Post by Daniel P Huds » Thu, 05 Sep 1996 04:00:00





>>Is the pointer of 'unsighed char' == the pointer of 'char'!?
>A pointer to char isn't directly compatible with a pointer to unsigned
>char in that you can't directly assign one to the other. Casting between
>these types (especially to pointer to unsigned char) is one of the more
>benign pointer casts. However if you can avoid doing any pointer casts.
>Perhaps if you post more details about what you want to do somebody
>might come up with a better approach.

 Maybe I'm thinking of C++, but I don't beleive a char is
 guarenteed to be either signed or unsigned, ergo his question
 is implementaiton dependant. Now a signed char* != unsigned char*
 is a true statement.
 
 
 

pointer of 'unsigned char' == 'char'!?

Post by Ken Pizzi » Thu, 05 Sep 1996 04:00:00




Quote:>if you have the following:

>unsigned char       *uchrPtr;
>signed char *chrPtr;

>Then `*uchrPtr` (ie. contents of what `uchrPtr` is pointing to) can
>range in values from -127 to +127 (decimal)
>and `*chrPtr` (ie. contents of what `chrPtr` is pointing to) can range
>in values from 0 to 255 (decimal).

You got those two ranges backwards.

#pragma nit_pick on
Furthermore, the ranges quoted above are merely the minimum guaranteed by
the standard.  On any given implementation the ramges may be larger.
In fact it is *very* common for the bottom of the signed character
range to be -128.  A portable application may not rely on an implementation
supporting ranges larger than those quoted above, but neither may it
assume that numbers outside those ranges are unsupported.
#pragma nit_pick off

                --Ken Pizzini

 
 
 

pointer of 'unsigned char' == 'char'!?

Post by Kaz Kylhe » Thu, 05 Sep 1996 04:00:00






>>>Is the pointer of 'unsighed char' == the pointer of 'char'!?

>>A pointer to char isn't directly compatible with a pointer to unsigned
>>char in that you can't directly assign one to the other. Casting between
>>these types (especially to pointer to unsigned char) is one of the more
>>benign pointer casts. However if you can avoid doing any pointer casts.
>>Perhaps if you post more details about what you want to do somebody
>>might come up with a better approach.

> Maybe I'm thinking of C++, but I don't beleive a char is
> guarenteed to be either signed or unsigned, ergo his question
> is implementaiton dependant. Now a signed char* != unsigned char*
> is a true statement.

I don't think so. A char and unsigned char are distinct types, even if char
happens to be implemented using unsigned quantities. Pointers to these two
can be cast back and forth because their alignment restrictions are the
same.  But when you dereference the result of such a conversion, you are
making an implicit assumption about the compatibility of the underlying
bit patterns whether or not your implementation of 'char' is signed or
not.

C's type rules are not implementation-defined.

 
 
 

pointer of 'unsigned char' == 'char'!?

Post by Lawrence Kirb » Wed, 11 Sep 1996 04:00:00






>>>Is the pointer of 'unsighed char' == the pointer of 'char'!?

>>A pointer to char isn't directly compatible with a pointer to unsigned
>>char in that you can't directly assign one to the other. Casting between
>>these types (especially to pointer to unsigned char) is one of the more
>>benign pointer casts. However if you can avoid doing any pointer casts.
>>Perhaps if you post more details about what you want to do somebody
>>might come up with a better approach.

> Maybe I'm thinking of C++, but I don't beleive a char is
> guarenteed to be either signed or unsigned,

It is guaranteed to be one or the other. That means it behaves like a signed
char or an unsigned char on that implementation except for the compatibility
issue.

Compare with signed char vs. short. An implementation may use the same
representation for both but even in that case they are distinct,
incompatible types.

Quote:> ergo his question
> is implementaiton dependant.

Certainly whether char is signed or unsigned is implementation-defined.

Quote:> Now a signed char* != unsigned char*
> is a true statement.

True but char is still a distinct type from both signed char and
unsigned char even though is shares the properties of one of them.

--
-----------------------------------------


-----------------------------------------

 
 
 

1. How can I read 6-bit words from an 'unsigned char' array?

Hi,

I have an array of "unsigned char"s (array size=141312, I know...I
know... it's big). It acts as a buffer containing data read from a file.
I want to read the data contained inside this array 6 (six) bits at a
time. Since each unsigned char is 8 (eight) bits, I'll end up extracting
the data 8 bits at a time if I just read each element into an "unsigned
char" variable. For example I may have something like this in the
buffer:

   001110011011101100111000...

If I were to read this into an "unsigned char" variable (which repeats
inside a loop), I'd get the buffer split up like this:

   00111001 - 10111011 - 00111000...

But what I really want is being able to read 6 (six) bits at a time,
essentially getting:

   001110 - 011011 - 101100 - 111000...

and put each one of these 6-bit words into a variable contained in a
loop.

Does anyone know of an *efficient* algorithm to do this?

Thanks in advance,
Parsa

2. Help available in Boston?

3. all man pages show '-' chars as '???'

4. SS5 network w/NIS+ is deteriorating; why ?

5. What's the default type in AIX between signed and unsigned char ?

6. what is the ORB?

7. drivers/char/Kconfig:640: can't open file "drivers/char/ipmi/Kconfig"

8. Shouks I switch II + where to get it

9. A quick question: Does 'grep' support TAB escape char ?

10. How to delete file with '-' char

11. Q about '~' char in programs.

12. ASCII char codes in 'tip'

13. Q about '~' char in programs.