Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is u_char a standard?

Tags:

Just curious if u_char is a standard. I've always used it assuming it was defined along with uintX_t types and so on. But am seeing some of our code base transition from u_char to "unsigned char" with a reason "so users don't have to define u_char themselves"..

like image 414
Jason Avatar asked Dec 17 '09 01:12

Jason


People also ask

What is U_char in C?

unsigned char is a character datatype where the variable consumes all the 8 bits of the memory and there is no sign bit (which is there in signed char). So it means that the range of unsigned char data type ranges from 0 to 255.

What is a Uchar?

A UCHAR is an 8-bit integer with the range: 0 through 255 decimal. Because a UCHAR is unsigned, its first bit (Most Significant Bit (MSB)) is not reserved for signing.

Why do we have unsigned char?

The basic ASCII values are in range 0 to 127. The rest part of the ASCII is known as extended ASCII. Using char or signed char we cannot store the extended ASCII values. By using the unsigned char, we can store the extended part as its range is 0 to 255.

Is an unsigned char a byte?

An unsigned data type that occupies 1 byte of memory. Same as the byte datatype. The unsigned char datatype encodes numbers from 0 to 255. For consistency of Arduino programming style, the byte data type is to be preferred.


3 Answers

The string u_char does not appear in this draft of the C standard:

http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf

It's not required by POSIX either, as far as I know.

I think it's in BSD (sys/types.h), and Windows (winsock.h). I would not consider either one to be "a standard" - they aren't formal standards, and they certainly aren't part of standard C, but they are clearly defined and documented.

like image 116
Steve Jessop Avatar answered Sep 23 '22 08:09

Steve Jessop


No, u_char is non-standard. If you need to use a standard type that's equivalent to u_char, you can use uint8_t which is part of the C99 standard library (check your specific platforms/compilers for C99-compliance). stdint.h defines this type (along with many other specific integral types). This Wikipedia article contains more information about stdint.h.

like image 10
Emerick Rogul Avatar answered Sep 23 '22 08:09

Emerick Rogul


It's not present in any older header files (except certain specific areas, like Kerberos and networking headers), and not a built-in type in any compiler I know of.

like image 4
wallyk Avatar answered Sep 23 '22 08:09

wallyk