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

need help abt bit fields & arrays

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



Joined: 06 Mar 2007
Posts: 92
Location: Pune,India

View user's profile Send private message AIM Address Yahoo Messenger

need help abt bit fields & arrays
PostPosted: Fri Mar 28, 2008 3:32 am     Reply with quote

Dear Sir,
I am using CCS PCM C Compiler, Version 4.052, 40286
In my code i defined array like this,
Code:
const unsigned int32 RPM[21] = {73171,52174,33333,28571,25000,22222,20339,20000,18750,15000,14634,13333,12000,10909,7500,7059,6667,6316,5714,5217,5000};
const signed int16 C1_SLP[20] = {31,31,56,26,106,16,184,14,14,14,14,14,14,14,14,14,14,14,-166,31};
const unsigned int16 C1_DLY[20] = {8740,6232,3981,2937,2569,1420,1299,1056,990,792,772,704,633,576,396,373,352,333,302,623};
const signed int16 C2_SLP[20] = {31,31,65,25,25,25,25,25,25,196,21,21,63,16,16,16,16,16,-133,31};
const unsigned int16 C2_DLY[20] = {8740,6232,3981,2778,2431,2160,1977,1944,1823,1458,1179,1074,967,697,479,451,426,404,365,623};
const signed int16 C3_SLP[20] = {48,23,23,23,80,47,97,12,12,12,12,12,12,12,12,12,12,12,-182,31};
const unsigned int16 C3_DLY[20] = {8740,4783,3056,2619,2292,1420,1073,944,885,708,691,630,567,515,354,333,315,298,270,623};

but unnecessarily i am wasting space i.e.
in RPM[21] = max data range is 17 bit but i my allocation is 32 bit (const unsigned int32),
C1_SLP[20] = max data range is 9 bit but i my allocation is 16 bit(const signed int16),
like wise others,
So,By using bit fields i want to save memory space
Can you plz help me how to assign these arrays by using bit fields,Also Plz tell me how to access it by example,
_________________
Thank You,
With Best Regards,
Deepak.
Matro
Guest







PostPosted: Fri Mar 28, 2008 3:53 am     Reply with quote

My advice is :
Just divide your values by 2 to store them (the lack of accuracy will not be visible).
A simple ">>" divides by 2 and "<<" reverts the process.
You will save space and executing time. ;-)

Arrays of bits would be possible, but the executing time will increase a lot.

Matro.
deepakomanna



Joined: 06 Mar 2007
Posts: 92
Location: Pune,India

View user's profile Send private message AIM Address Yahoo Messenger

need help about bit fields
PostPosted: Mon Mar 31, 2008 10:01 pm     Reply with quote

Can you explain with example ..Please
_________________
Thank You,
With Best Regards,
Deepak.
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