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

Function declaration order

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



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

Function declaration order
PostPosted: Sun Aug 23, 2020 10:08 am     Reply with quote

Hi All,

When declaring structs the variables inside are ordered by their size: floats first, then int16s, then int8s and ints1, as needed... right.

So my question is if this also applies to function declarations?

voids first, int16 types, etc...

I've always organized them by functionality/or resource without any issues... but lately I've been using a ton of structs and it got me thinking it might matter here too... and with variable declarations too by extension.

I'd appreciate any "good practices" recommendation here... i have a massive code cleanup going on.

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Ttelmah



Joined: 11 Mar 2010
Posts: 19509

View user's profile Send private message

PostPosted: Sun Aug 23, 2020 10:22 am     Reply with quote

The compiler re-orders the functions to make them fit in the available
memory pages.
The algorithm is 'reasonable', but not 'brilliant'. So (for instance), if you
have a chip that has a particular page size, and allows four pages, then
declare five large functions, though it is actually possible to fit them
(perhaps fitting the two smallest functions into one page), the compiler
may fail to spot this. It gets it to work 99% of the time where it is
possible.
avatarengineer



Joined: 13 May 2013
Posts: 51
Location: Arizona

View user's profile Send private message Visit poster's website

int1 in structs
PostPosted: Mon Aug 31, 2020 2:33 pm     Reply with quote

int1 are created from a byte,
therefore whether you have 1 int1 or 8, both conditions use a byte.

Code:

struct {                           
int1 F4Khz,F2KHz,F1KHz,Blink;
int1 FastBlink,SlowBlink,StnbyBlink,TickSec;
int1 Ops1mS,Ops5mS,Ops10mS,Ops50ms;
int1 Ops250ms,a,b,c; 
} Timerbits;

I add dummies in the struct to remind me of unused
int1 bits in the byte.


Also, I asked the question before about order of PICC declarations
and I recall a reverse order, int1 bytes, bytes, words, longs,floats.
Can this be verified?
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Aug 31, 2020 6:21 pm     Reply with quote

Hmm. perhaps the 'program_name.sym' file has what you need to know ?? Pretty sure it's the one with the RAM and ROM allocations in it ?

Jay
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