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 support@ccsinfo.com

Any idea what is wrong with this union?

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



Joined: 15 Jun 2016
Posts: 23

View user's profile Send private message AIM Address

Any idea what is wrong with this union?
PostPosted: Sun Jul 10, 2016 1:28 pm     Reply with quote

Here are relevant snippets of code

Code:

union LONG_UNION
{
   signed int32   sl;
   unsigned int32   ul;
   signed int16   si[2];
   unsigned int16   ui[2];
   signed int8      sc[4];
   unsigned int8   uc[4];
};


union LONG_UNION   ulActiveAddr;

      ulActiveAddr.uc[3] = 0x00;
      ulActiveAddr.uc[2] = 0x00;
      ulActiveAddr.uc[1] = 0x01;
      ulActiveAddr.uc[0] = 0x00;

   printf("Part Addr = %8X, %2X, %2X, %2X, %2X\n",
      ulActiveAddr.ul,
      ulActiveAddr.uc[3],
      ulActiveAddr.uc[2],
      ulActiveAddr.uc[1],
      ulActiveAddr.uc[0]);



Prints the following
Part Addr = 00000000, 00, 00, 01, 00

I think it should print
Part Addr = 00000100, 00, 00, 01, 00

I'm using this to access an address on an external eeprom.
jeremiah



Joined: 20 Jul 2010
Posts: 1320

View user's profile Send private message

PostPosted: Sun Jul 10, 2016 1:41 pm     Reply with quote

Use %LX instead of just %X for the larger data types.
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