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

struct with bit-array members

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



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

struct with bit-array members
PostPosted: Sat Nov 29, 2008 4:24 am     Reply with quote

Colleagues,

Could you look at the code below and see if there's anything obviously wrong with it?

Code:
const int8  iN_ELECTRODES = 4;
const int8  iN_PRODUCTS = 2;

typedef struct
{
   int1 bProductMap[iN_PRODUCTS][4 * iN_ELECTRODES];
   int1 bSumMap[2 * iN_PRODUCTS];
}
structRecipe;

/* const */ structRecipe g_sRECIPE = {  // ideally, this variable would sit in ROM, but RAM is ok too
   {
      {1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0},
      {0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1}
   },
   {1,0,0,1}
};


g_sRECIPE.iSumMap[i] compiles, but it doesn't output the correct values of the array members. At the same time, g_sRECIPE.bProductMap[i][j] works fine for any i and j in range. I was expecting more problems with a 2-D array rather than 1-D. Even if I remove bProductMap from the struct, I can't access iSumMap.

I'd be happy to post more code if needed.

Thanks!
- Nick

EDIT: In response to FvM. Compiler v4.071. Target PIC18LF4525.

P.S. May be it will seem clearer in the morning.
_________________
Read the label, before opening a can of worms.


Last edited by kender on Sat Nov 29, 2008 4:51 am; edited 3 times in total
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Nov 29, 2008 4:43 am     Reply with quote

As a compiler specific bug must be assumed, it's important to know the compiler type and version. Otherwise, I just can say, the code looks O.K. Also a minimal example reproducing the error would be helpful.

Regards,
Frank
Ttelmah
Guest







PostPosted: Sat Nov 29, 2008 11:10 am     Reply with quote

What type are you putting the result 'into'?.
There have been a number of posts in the past, about CCS, having real 'oddities' with int1 types, when moving them into other types. Tried compiling the code, and looked at the listing. Accessing g_SRECIPE.bSumMap[0], put all four bits into an int8 variable, rather than accessing just the bottom bit. The addressing was correct. Adding an int1 cast to the operation, made the code work. So:

temp = (int1)g_SRECIPE.bSumMap[0];

gave a working value, as did copying the value into another int1 variable. It appears to be a 'global' problem with int1 values, in some circumstances The two dimensional array, results in a correct bit test.
I'd suggest that anyone using int1, gets into the 'habit' of casting them when reading them, which seems to fix this problem.

Best Wishes
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Mon Dec 01, 2008 1:18 am     Reply with quote

The only thing that ultimately helped was padding the bit array to 8 members. Without padding it didn't work, even with casting to int1. With padding it does work even without casting to int1.

Here are some peculiar results that I got in the process:

Code:

// g_sRECIPE.bSumMap = {1,0,0,1};

for (i = 0; i < iN_PRODUCTS * 2; ++i)
{
   printf("%u", g_sRECIPE.bSumMap[i]);   // 9999

   printf("%u", (int1)g_sRECIPE.bSumMap[i]);   // 1111

   b = g_sRECIPE.bSumMap[i];
   printf("%u", b);   // 1111

   b = (int1)g_sRECIPE.bSumMap[i];
   printf("%u", b);   // 1111
}

_________________
Read the label, before opening a can of worms.
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