469,327 Members | 1,180 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

8 bit integer type

typedef char int(myint8);

the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.

I have allso tryed defining my own type, but got lost when i had to
implement all the operator (==, -=, +=, ++, --, etc.) and besides it
seemed a really stupid way to go about it.

So please i anyone holds an answer, let me hear it.

Regards

Aug 29 '07 #1
11 21698
On 2007-08-29 11:45, za******@gmail.com wrote:
typedef char int(myint8);

the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.
In what way does a char differ in behaviour from an int, except for the
range of values it can hold?

--
Erik Wikström
Aug 29 '07 #2
On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-08-29 11:45, zacar...@gmail.com wrote:
typedef char int(myint8);
the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.

In what way does a char differ in behaviour from an int, except for the
range of values it can hold?

--
Erik Wikström
Of course it doesnt differ much, but it does differ, fx. what do you
think happened when i first head about the stdint.h and wanted to try
out the uint8-t?

@code
uint8_t var = 7;
std::cout << var;
@code

BEEP! it said.
Imagine my surprise. and integer type making funny noises?
Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter, well that depends, but the goal of
this post was only to make certain that a real 8 bit integer type or
an easy soluton doesnt allready excist.

Aug 29 '07 #3
On 2007-08-29 12:35, za******@gmail.com wrote:
On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia.comwrote:
>On 2007-08-29 11:45, zacar...@gmail.com wrote:
typedef char int(myint8);
the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.

In what way does a char differ in behaviour from an int, except for the
range of values it can hold?

--
Erik Wikström

Of course it doesnt differ much, but it does differ, fx. what do you
think happened when i first head about the stdint.h and wanted to try
out the uint8-t?

@code
uint8_t var = 7;
std::cout << var;
@code

BEEP! it said.
Imagine my surprise. and integer type making funny noises?
Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter, well that depends, but the goal of
this post was only to make certain that a real 8 bit integer type or
an easy soluton doesnt allready excist.
Yes, I see. This is of course because uint8_t is just a typedef of an
unsigned char. I don't think anyone but the compiler vendor or library
vendor can fix this.

--
Erik Wikström
Aug 29 '07 #4
za******@gmail.com wrote:
On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia.comwrote:
>On 2007-08-29 11:45, zacar...@gmail.com wrote:
>>typedef char int(myint8);
the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.
In what way does a char differ in behaviour from an int, except for the
range of values it can hold?

--
Erik Wikström

Of course it doesnt differ much, but it does differ, fx. what do you
think happened when i first head about the stdint.h and wanted to try
out the uint8-t?

@code
uint8_t var = 7;
std::cout << var;
@code

BEEP! it said.
Imagine my surprise. and integer type making funny noises?
Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter, well that depends, but the goal of
this post was only to make certain that a real 8 bit integer type or
an easy soluton doesnt allready excist.
struct int8bit
{
unsigned int number : 8;
}

then implement a class which does everything you want to do with this.
Aug 29 '07 #5
On 29 Aug., 13:24, anon <a...@no.nowrote:
zacar...@gmail.com wrote:
On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-08-29 11:45, zacar...@gmail.com wrote:
>typedef char int(myint8);
the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.
In what way does a char differ in behaviour from an int, except for the
range of values it can hold?
--
Erik Wikström
Of course it doesnt differ much, but it does differ, fx. what do you
think happened when i first head about the stdint.h and wanted to try
out the uint8-t?
@code
uint8_t var = 7;
std::cout << var;
@code
BEEP! it said.
Imagine my surprise. and integer type making funny noises?
Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter, well that depends, but the goal of
this post was only to make certain that a real 8 bit integer type or
an easy soluton doesnt allready excist.

struct int8bit
{
unsigned int number : 8;

}

then implement a class which does everything you want to do with this.- Skjul tekst i anførselstegn -

- Vis tekst i anførselstegn -
ah yes, two problems reamins however.
1. How much space does this new type use in memory? i mean is it just
an 32 bit int with an 8 bit limitation or is it infact an 8 bit int?
2. this vould not be used as a regular type but would have to be
called like int8bit.number, this is not that important, but really it
would be tha same as writing int(char), eg. more enoying code.

Aug 29 '07 #6
za******@gmail.com wrote:
On 29 Aug., 13:24, anon <a...@no.nowrote:
>zacar...@gmail.com wrote:
>>On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-08-29 11:45, zacar...@gmail.com wrote:
typedef char int(myint8);
the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.
In what way does a char differ in behaviour from an int, except for the
range of values it can hold?
--
Erik Wikström
Of course it doesnt differ much, but it does differ, fx. what do you
think happened when i first head about the stdint.h and wanted to try
out the uint8-t?
@code
uint8_t var = 7;
std::cout << var;
@code
BEEP! it said.
Imagine my surprise. and integer type making funny noises?
Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter, well that depends, but the goal of
this post was only to make certain that a real 8 bit integer type or
an easy soluton doesnt allready excist.
struct int8bit
{
unsigned int number : 8;

}

then implement a class which does everything you want to do with this.- Skjul tekst i anførselstegn -

- Vis tekst i anførselstegn -

ah yes, two problems reamins however.
1. How much space does this new type use in memory? i mean is it just
an 32 bit int with an 8 bit limitation or is it infact an 8 bit int?
It would take 32 bit memory, but it would be 8-bit unsigned int.
2. this vould not be used as a regular type but would have to be
called like int8bit.number, this is not that important, but really it
would be tha same as writing int(char), eg. more enoying code.
You could encapsulate it in a class.
Aug 29 '07 #7
On 29 Aug., 14:52, anon <a...@no.nowrote:
zacar...@gmail.com wrote:
On 29 Aug., 13:24, anon <a...@no.nowrote:
zacar...@gmail.com wrote:
On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-08-29 11:45, zacar...@gmail.com wrote:
typedef char int(myint8);
the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.
In what way does a char differ in behaviour from an int, except for the
range of values it can hold?
--
Erik Wikström
Of course it doesnt differ much, but it does differ, fx. what do you
think happened when i first head about the stdint.h and wanted to try
out the uint8-t?
@code
uint8_t var = 7;
std::cout << var;
@code
BEEP! it said.
Imagine my surprise. and integer type making funny noises?
Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter, well that depends, but the goal of
this post was only to make certain that a real 8 bit integer type or
an easy soluton doesnt allready excist.
struct int8bit
{
unsigned int number : 8;
}
then implement a class which does everything you want to do with this.- Skjul tekst i anførselstegn -
- Vis tekst i anførselstegn -
ah yes, two problems reamins however.
1. How much space does this new type use in memory? i mean is it just
an 32 bit int with an 8 bit limitation or is it infact an 8 bit int?

It would take 32 bit memory, but it would be 8-bit unsigned int.
2. this vould not be used as a regular type but would have to be
called like int8bit.number, this is not that important, but really it
would be tha same as writing int(char), eg. more enoying code.

You could encapsulate it in a class.- Skjul tekst i anførselstegn -

- Vis tekst i anførselstegn -
not that it matters much cause the solution is not what im looking
for, but what do you mean by "encapsulate in a class"?

Aug 29 '07 #8
za******@gmail.com wrote:
>>2. this vould not be used as a regular type but would have to be
called like int8bit.number, this is not that important, but really it
would be tha same as writing int(char), eg. more enoying code.
You could encapsulate it in a class.

not that it matters much cause the solution is not what im looking
for, but what do you mean by "encapsulate in a class"?
You can do the same for char (or unsigned char, not sure what you
using). By encapsulating it in a class, you would have to overload all
operators you are going to use (+, - , etc) and you would have to write
operator<< for that class. That way you would not have to cast when
sending to a stream.
Aug 29 '07 #9
Hi!

za******@gmail.com schrieb:
Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter,
which can be reduced, but would also reduce the verbosity:

std::cout << +var;

The unary operator + will implicitly cast the value to int. Hard to
read, though, so it's not good for maintenance.

Frank
Aug 29 '07 #10
Wouldn't compilers still align data on word or half-word bounderies in
memory, so using a char doesn't really save any bits?

Or I could be imagining things.

--n

"Frank Birbacher" <bl************@gmx.netwrote in message
news:5j***********@mid.dfncis.de...
Hi!

za******@gmail.com schrieb:
>Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter,

which can be reduced, but would also reduce the verbosity:

std::cout << +var;

The unary operator + will implicitly cast the value to int. Hard to
read, though, so it's not good for maintenance.

Frank

Aug 31 '07 #11
On 2007-08-31 05:59, Geoff wrote:
"Frank Birbacher" <bl************@gmx.netwrote in message
news:5j***********@mid.dfncis.de...
>Hi!

za******@gmail.com schrieb:
>>Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter,

which can be reduced, but would also reduce the verbosity:

std::cout << +var;

The unary operator + will implicitly cast the value to int. Hard to
read, though, so it's not good for maintenance.
Please don't top-post and don't quote signatures.
Wouldn't compilers still align data on word or half-word bounderies in
memory, so using a char doesn't really save any bits?

Or I could be imagining things.
Yes you are, you are imagining that all computers work the same way,
imagine for example a computer that can align on half-word boundaries
and have a 16 bit word, that means no padding and no loss.

--
Erik Wikström
Aug 31 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Simon G Best | last post: by
11 posts views Thread by Jason Heyes | last post: by
1 post views Thread by Joe | last post: by
4 posts views Thread by FatboyCanteen | last post: by
35 posts views Thread by Frederick Gotham | last post: by
3 posts views Thread by veeman | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.