473,549 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Button1C lick(Sender: TObject);
var
onebyte: byte;
^^^^

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


char.

--
/-- Joona Palaste (pa*****@cc.hel sinki.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********@hip erfect.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.Button1C lick(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********@hip erfect.com> pt*****@hiperfe ct.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.hel sinki.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********@hip erfect.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.Button1C lick(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*****@hiperfe ct.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*****@hiperfe ct.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********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 13 '05 #10

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

Similar topics

2
11150
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 supported. Does anyone have a routine that will allow VB6 to read a C++ unsigned short int? Thanks Del
27
4184
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 the first 8-bits for example. For me, I think it would be best if I can declare the 32-bits like this: unsigned char bits;
16
10087
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 integer B and so on.
61
3313
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 there a way to remove the ones with size predefined from the autolisting of types when I am declaring something? -- To Email Me, ROT13 My Shown Email...
3
4279
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 float = 4 byte double =8 byte long double =80 byte
6
1678
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 not eg a colour object). Because the colour will be in ARGB colour space the integer needs to specify all four bytes. But if I try to pass the...
1
1883
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 ' Global Union Variables: Public Shared crc_value As word_byte ' system crc value Public Shared adc_value As word_byte ' adc value...
11
2216
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
1640
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 fairly small numbers as INTEGER. thanks, David
0
7471
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7740
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7830
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5387
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5111
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3517
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3496
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1082
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.