473,408 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Is there a integer data type of one byte in gcc?

Ptp
is there a integer data type of one byte in gcc?
I know delphi have fundamental integer types include byte, shortint...
the byte types is unsigned 8-bit, such as below:

procedure TForm1.Button1Click(Sender: TObject);
var
onebyte: byte;
^^^^

¡° ¨Ó·½:¡E¨}¬ü®a±ÚÁ`¹ë hiperfect.com¡E[FROM: localhost]
Nov 13 '05 #1
18 16692
Ptp <pt*****@hiperfect.com> scribbled the following:
is there a integer data type of one byte in gcc?


char.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"To err is human. To really louse things up takes a computer."
- Anon
Nov 13 '05 #2
In article <48********@hiperfect.com>, Ptp wrote:
is there a integer data type of one byte in gcc?
I know delphi have fundamental integer types include byte, shortint...
the byte types is unsigned 8-bit, such as below:

procedure TForm1.Button1Click(Sender: TObject);
var
onebyte: byte;
^^^^

I don't know about gcc, but standard C has the char type, which
is one byte by definition. One byte is CHAR_BIT bits (in
<limits.h>), usually 8.
--
Andreas Kähäri
Nov 13 '05 #3
>> Is there an integer data type of one byte in gcc?

char.


I think he meant 8 bits.

Is uint8_t guaranteed to be 8 bits wide on every platform?

Nov 13 '05 #4
In <48********@hiperfect.com> pt*****@hiperfect.com (Ptp) writes:
is there a integer data type of one byte in gcc?


Not one, but three, and not only in gcc but in any conforming C compiler:
char, signed char, unsigned char.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #5
Grumble <in*****@kma.eu.org> scribbled the following:
Is there an integer data type of one byte in gcc?
char.

I think he meant 8 bits.
char is guaranteed to be at least 8 bits wide on every platform. If the
OP wants a type that is exactly 8 bits wide, then I would want to know
why.
Is uint8_t guaranteed to be 8 bits wide on every platform?


I'd figure so, on platforms that support it in the first place.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Outside of a dog, a book is a man's best friend. Inside a dog, it's too dark
to read anyway."
- Groucho Marx
Nov 13 '05 #6
Andreas Kahari wrote:

In article <48********@hiperfect.com>, Ptp wrote:
is there a integer data type of one byte in gcc?
I know delphi have fundamental integer types include byte, shortint...
the byte types is unsigned 8-bit, such as below:

procedure TForm1.Button1Click(Sender: TObject);
var
onebyte: byte;
^^^^


I don't know about gcc, but standard C has the char type, which
is one byte by definition.


If one were going to use a one byte integer
for mathematical purposes, rather than for string characters,
I would suggest choosing either "signed char" or "unsigned char",
instead of plain "char".

--
pete
Nov 13 '05 #7
Ptp wrote:
is there a integer data type of one byte in gcc?


char, signed char, unsigned char

--
Martin Ambuhl

Nov 13 '05 #8
pt*****@hiperfect.com (Ptp) wrote in message news:<48********@hiperfect.com>...
is there a integer data type of one byte in gcc?


If gcc is a conformant C compiler (and it isn't always), it has three
types guaranteed to be at least eight bits wide: char, unsigned char,
and signed char.

What's the difference between signed and unsigned? One type can hold a
sign and has been modified in an implementation-specified way to do
it, the other cannot hold a sign and has behavior more stringently
defined by the Standard in the various edge cases. One of the edge
cases is wrap-around: If you do

#include <limits.h>

unsigned char foo(void)
{
unsigned char i = UCHAR_MAX;
i++;
return(i);
}

the return value from foo() is defined (it is 0). If, however, you do

#include <limits.h>

signed char bar(void)
{
signed char i = CHAR_MAX;
i++;
return(i);
}

the return value from bar() is implementation-dependent and is allowed
to be a trap representation (that is, one that sends the machine into
a tizzy).

So, if you want to treat your at-least-eight-bits-wide values as an
unsigned type with a strictly defined behavior in case of overflow,
use unsigned char. If you need to hold a sign, use signed char or
char.
Nov 13 '05 #9
Dan Pop wrote:
pt*****@hiperfect.com (Ptp) writes:
is there a integer data type of one byte in gcc?


Not one, but three, and not only in gcc but in any conforming C
compiler: char, signed char, unsigned char.


At last a correct answer. However, of the three, using char in
arithmetical expressions is likely to lead to unexpected results.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #10
August Derleth wrote:
....
So, if you want to treat your at-least-eight-bits-wide values as an
unsigned type with a strictly defined behavior in case of overflow,
use unsigned char. If you need to hold a sign, use signed char or
char.


No, use signed char exclusively.

Jirka

Nov 13 '05 #11
On Tue, 21 Oct 2003 12:21:39 +0200, Grumble <in*****@kma.eu.org> wrote
in comp.lang.c:
Is there an integer data type of one byte in gcc?


char.


I think he meant 8 bits.

Is uint8_t guaranteed to be 8 bits wide on every platform?


Yes it is. But not all platforms can provide uint8_t.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #12
On 21 Oct 2003 11:25:30 -0700, li***************@yahoo.com (August
Derleth) wrote in comp.lang.c:
pt*****@hiperfect.com (Ptp) wrote in message news:<48********@hiperfect.com>...
is there a integer data type of one byte in gcc?


If gcc is a conformant C compiler (and it isn't always), it has three
types guaranteed to be at least eight bits wide: char, unsigned char,
and signed char.


[snip]

I know you didn't mean it this way, but it came out quite wrong.

A version of gcc or any other compiler conforming to just ANSI C89 has
at least 9 integer types guaranteed to be, as you put it, "at least
eight bits wide".

In addition to the three you mentioned, signed and unsigned short,
signed and unsigned int, and signed and unsigned long are guaranteed
to be at least eight bits wide. In fact they are guaranteed to be
more than eight bits wide. "more than" is a super set of "at least".

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #13
Jack Klein wrote:
"more than" is a super set of "at least".


A subset, not a superset.

Jeremy.
Nov 13 '05 #14
In <3F***************@yahoo.com> CBFalconer <cb********@yahoo.com> writes:
At last a correct answer. However, of the three, using char in
arithmetical expressions
It's not as much using char in arithmetical expressions as it is using
char as an arithmetic type that can cover more than 0..127. Within this
range, plain char works like a charm.
is likely to lead to unexpected results.


If you're lucky. If you aren't, the unexpected results will show up
when someone else tries to use your program on a different platform. And
this is the usual case, because most people know the signedness of char
on their platform, so they don't get unexpected results.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #15
On 21 Oct 2003 11:37:00 GMT, Joona I Palaste <pa*****@cc.helsinki.fi>
wrote:
char is guaranteed to be at least 8 bits wide on every platform. If the
OP wants a type that is exactly 8 bits wide, then I would want to know
why.
Is uint8_t guaranteed to be 8 bits wide on every platform?


I'd figure so, on platforms that support it in the first place.

I'm not 100% sure that a char isn't *ALWAYS* 8-bits. For the most
part, writing C code to depend upon the size of a given data type is
rather risky. It can change at a moments notice with a compiler
upgrade. Everything's pretty much based off the int's being the
natural machine word size, which is 16 for DOS days, 32 for Windows'95
days, 64 for VAX VMS, and other mini-computers, etc... If you want a
language that can guarantee your data file will always be 20 megs per
record, program in COBOL. Otherwise, if you want a language that can
give you the power to write small and fast databases, then use C....
In order to make C work the same on so many platforms, C must be
flexible enough to be able to meet every computers needs, not just
intel based cpus.....
Nov 13 '05 #16
On Tue, 21 Oct 2003 20:35:54 +0200, Jirka Klaue
<jk****@ee.tu-berlin.de> wrote:
August Derleth wrote:
...
So, if you want to treat your at-least-eight-bits-wide values as an
unsigned type with a strictly defined behavior in case of overflow,
use unsigned char. If you need to hold a sign, use signed char or
char.


No, use signed char exclusively.

Actually, to be equivilent to DELPHI's "BYTE" you'd use unsigned
char. Pascal/Delphi has shortint types that are equivilent to signed
char.....
Nov 13 '05 #17
John H. Guillory <jo***@mlc-hosting.net> writes:
On 21 Oct 2003 11:37:00 GMT, Joona I Palaste <pa*****@cc.helsinki.fi>
wrote:
char is guaranteed to be at least 8 bits wide on every platform. If the
OP wants a type that is exactly 8 bits wide, then I would want to know
why.
Is uint8_t guaranteed to be 8 bits wide on every platform?
I'd figure so, on platforms that support it in the first place.

I'm not 100% sure that a char isn't *ALWAYS* 8-bits.


char isn't always 8 bits. It's guaranteed by the standard to be at
least 8 bits, but there are implementations (on DSPs, I think) on
which it's 16 or 32 bits. Some systems, mostly older ones, have, for
example, 9-bit bytes; I' don't know whether those systems have
conforming C implementations.
For the most part, writing C code to depend upon the size of a given
data type is rather risky. It can change at a moments notice with a
compiler upgrade. Everything's pretty much based off the int's
being the natural machine word size, which is 16 for DOS days, 32
for Windows'95 days, 64 for VAX VMS, and other mini-computers,
etc...


<OT><QUIBBLE>The VAX is a 32-bit system.</QUIBBLE></OT>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
(Note new e-mail address)
Nov 13 '05 #18
John H. Guillory <jo***@mlc-hosting.net> wrote in message news:<rh********************************@4ax.com>. ..
On 21 Oct 2003 11:37:00 GMT, Joona I Palaste <pa*****@cc.helsinki.fi>
wrote:
char is guaranteed to be at least 8 bits wide on every platform. If the
OP wants a type that is exactly 8 bits wide, then I would want to know
why.
Is uint8_t guaranteed to be 8 bits wide on every platform?


I'd figure so, on platforms that support it in the first place.

I'm not 100% sure that a char isn't *ALWAYS* 8-bits.

A char in C is guaranteed to be at least eight bits. It may well be
more. And on more than a few DSPs, it is. C99 uint8_t is always
exactly eight bits wide. If the implementation does not provide such
a type, type typedef for uint8_t will *not* exist. So using uint8_t
will always give you an unsigned 8-bit int, but will fail to compile
on any implementations not supporting such a type.
Nov 13 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Salgoud Dell | last post by:
C++ has a variable type 'unsigned short int.' I am trying to write a VB6 program that prints these out of a file made originally by C++. However, the unsigned short integer (1-65535) is not...
27
by: Daniel Lidström | last post by:
Hello! I want to work with individual bytes of integers. I know that ints are 32-bit and will always be. Sometimes I want to work with the entire 32-bits, and other times I want to modify just...
16
by: Dave | last post by:
Hi all, I have a 4 byte char array with the binary data for two 16-bit signed integers in it like this: Index 3 2 1 0 Data Bh Bl Ah Al Where Bh is the high byte of signed 16-bit...
61
by: John Baker | last post by:
When declaring an integer, you can specify the size by using int16, int32, or int64, with plain integer being int32. Is integer the accepted default in the programming community? If so, is...
3
by: Imayam | last post by:
Hi .! This is my first post to this community..! I am trying to use 64 bit data in 16 Bit dos.Here i have a Borland C 3.1 Compiler in which i have data types int = 2 byte long = 4 byte...
6
by: John Dann | last post by:
I'm trying to use a third party .Net charting control. One of its methods takes a standard 4-byte integer as a parameter (to specify a colour actually, but it's done as a standard integer value and...
1
by: cmdolcet69 | last post by:
I'm having issues with the code below. I get the message that Uinteger is not defined. I need to make this data type as a unsigned integer. Public Class GlobalMembers Public com1 As MSCOMM...
11
by: cmdolcet69 | last post by:
Public Shared adc_value As word_byte Public Class byte_low_hi Public low_byte As Byte Public high_byte As Byte End Class pmsg(2) = CChar(adc_value.word16.high_byte)
3
by: David | last post by:
If I have a loop that has a max value of say 20 why would I not want to define the loop counter using a BYTE or SHORT as opposed to a INTEGER. It seems in most books or samples they define...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.