P
poison.summer
For instance, I'd like to use unsigned char as an 8-bit integer.
Can I use like
unsigned char a=0;
a++
Thanks a lot!
Can I use like
unsigned char a=0;
a++
Thanks a lot!
For instance, I'd like to use unsigned char as an 8-bit integer.
Can I use like
unsigned char a=0;
a++
Another point. Defining a parameter as char is pointeless. It will
always be converted to an int and will use an int print in automatic
memory.
Assuming 32-bit ints and the ASCII character set, must the compiler
generate code that passes 0x00000061 to foo?
I have seen compilers which will load 0x61 into the low byte of a
register and push that register onto the stack, leaving the rest of
the register alone. Yes, it did push a 32-bit value, but the top
24 bits were in an undetermined state.
Were these compilers broken, as far as the standard goes?
And, strictly speaking, would it be legal for a C compiler to generate
code which pushed a 16-bit value on the stack on a system with 32-bit
integers?
Kenneth Brody said:Emmanuel Delahaye wrote:
[...]Another point. Defining a parameter as char is pointeless. It will
always be converted to an int and will use an int print in automatic
memory.
Is this strictly true?
No.
Given the following:
void foo(char c)
{
... do stuff with 'c' ...
}
void myfunc(void)
{
foo('a');
}
Assuming 32-bit ints and the ASCII character set, must the compiler
generate code that passes 0x00000061 to foo?
I have seen compilers which will load 0x61 into the low byte of a
register and push that register onto the stack, leaving the rest of
the register alone. Yes, it did push a 32-bit value, but the top
24 bits were in an undetermined state.
Were these compilers broken, as far as the standard goes?
And, strictly speaking, would it be legal for a C compiler to generate
code which pushed a 16-bit value on the stack on a system with 32-bit
integers?
Emmanuel Delahaye wrote:
[...]Another point. Defining a parameter as char is pointeless. It will
always be converted to an int and will use an int print in automatic
memory.
Is this strictly true?
Given the following:
void foo(char c)
{
... do stuff with 'c' ...
}
void myfunc(void)
{
foo('a');
}
I have seen compilers which will load 0x61 into the low byte of a
register and push that register onto the stack, leaving the rest of
the register alone. Yes, it did push a 32-bit value, but the top
24 bits were in an undetermined state.
Were these compilers broken, as far as the standard goes?
No.
And, strictly speaking, would it be legal for a C compiler to generate
code which pushed a 16-bit value on the stack on a system with 32-bit
integers?
Thanks a lot! I am cooperating with others.
other people have defined
#define Byte unsigned char
so I have to use it.
So is the following a better way?
Byte a;
unsigned short tmp;
if(tmp>256)
tmp = 0;
tmp ++
a = tmp;
Kenneth said:Emmanuel Delahaye wrote:
[...]Another point. Defining a parameter as char is pointeless. It will
always be converted to an int and will use an int print in automatic
memory.
Is this strictly true?
Given the following:
void foo(char c)
{
... do stuff with 'c' ...
}
void myfunc(void)
{
foo('a');
}
Assuming 32-bit ints and the ASCII character set, must the compiler
generate code that passes 0x00000061 to foo?
I have seen compilers which will load 0x61 into the low byte of a
register and push that register onto the stack, leaving the rest of
the register alone. Yes, it did push a 32-bit value, but the top
24 bits were in an undetermined state.
Were these compilers broken, as far as the standard goes?
And, strictly speaking, would it be legal for a C compiler to generate
code which pushed a 16-bit value on the stack on a system with 32-bit
integers?
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
Kenneth Brody said:Emmanuel Delahaye wrote:
[...]Another point. Defining a parameter as char is pointeless. It will
always be converted to an int and will use an int print in automatic
memory.
Is this strictly true?
No.
Thanks a lot! I am cooperating with others.
other people have defined
#define Byte unsigned char
so I have to use it.
So is the following a better way?
Byte a;
unsigned short tmp;
if(tmp>256)
tmp = 0;
tmp ++
a = tmp;
Neil said:Kenneth Brody wrote: [...][...]void foo(char c)
{
... do stuff with 'c' ...
}
void myfunc(void)
{
foo('a');
}
Assuming 32-bit ints and the ASCII character set, must the compiler
generate code that passes 0x00000061 to foo?
The Poster did not say, but why assume 32 bits. If he has an 8 bit cpu
He should use the smallest variable possible, especially is RAM is
limited. For a 16 bit X86 still a savings. For a 32 bit cpu most
likely no help, and for some maybe worse.
Lawrence said:A better way for what?
How is tmp set?
If tmp starts as 255 or 256 and
UCHAR_MAX is 255 the final value of tmp
won't fit in a. What is this code supposed to do? In terms of code
efficiency you're probably better off using unsigned int than unsigned
short.
pete said:I'm guessing that he wants the count to go up from 0
and then roll over after 255,
but I'm assuming that he's not expressing himself well.
/* BEGIN new.c */
#include <stdio.h>
typedef unsigned char Byte;
int main(void)
{
Byte a;
unsigned count, tmp;
tmp = a = 0;
for (count = 3; count != 0; --count) {
do {
++tmp;
tmp &= 0xff;
a = (Byte)tmp;
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.