View previous topic :: View next topic |
Author |
Message |
vector
Joined: 07 Mar 2004 Posts: 7
|
why wont it printf struct correctly |
Posted: Tue Jun 08, 2004 10:57 pm |
|
|
Hi
I sneaked around this problem b4but would like to solve/understand it properly. why cant i printf a srtruct? and passing a struct doesnt work either.
<<code snip
printf("%x",flag); //this should print the sruct
my current fix
char tmp;
tmp=flag;
printf(%x",tmp);
//set up flags within status byte
struct flag_typ {
unsigned f_run:1; //run
unsigned f_htr:1; //heater
unsigned f_alm:1; //alarm flag
unsigned f_fan:1; //fan pin
unsigned f_ful:1; //memfull
unsigned f_cwl:1; //cool flag
unsigned f_spr:1; //spare
unsigned f_usr:1; //display current data (mod_ee) on
}flag; |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 08, 2004 11:49 pm |
|
|
You didn't say whether the error you're getting is a compile-time
error or a run-time error. (You also didn't give your compiler version).
I couldn't even compile it. It says "A numeric expression must
appear here".
Upon examining the code, my first thought was "printf is expecting
a char, I would guess, and you're giving it a type".
So my fix would be to cast it to a char. Like this:
printf("%x", (char)flag);
That compiles, and upon looking at the .LST file, it looks like it
should work. |
|
|
Guest
|
|
Posted: Wed Jun 09, 2004 12:11 am |
|
|
many thanks
I just had that same thought myself and tried the (char) trick and sure enough it works
cheers |
|
|
|