CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

why wont it printf struct correctly

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
vector



Joined: 07 Mar 2004
Posts: 7

View user's profile Send private message

why wont it printf struct correctly
PostPosted: Tue Jun 08, 2004 10:57 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jun 08, 2004 11:49 pm     Reply with quote

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








PostPosted: Wed Jun 09, 2004 12:11 am     Reply with quote

many thanks
I just had that same thought myself and tried the (char) trick and sure enough it works
cheers
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group