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

const var in ex. function

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



Joined: 21 Mar 2020
Posts: 44

View user's profile Send private message

const var in ex. function
PostPosted: Mon Sep 04, 2023 2:55 am     Reply with quote

Hello,
i have a value that I need for some calculations. Does it make sense to store it with the help of const in the flash.
Or is that too much.


Am I allowed to do this at all in a function that is in an external file?

void HV_INIT (void)
{
const unsigned int16 value=1000;
...
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19529

View user's profile Send private message

PostPosted: Mon Sep 04, 2023 4:51 am     Reply with quote

Yes, provided it is only wanted/used inside HV_INIT.

However do be aware that it is more efficient both in code size and speed
to not have things 'external'.
CCS historically was a single pass compiler, and even on compilers where
this is not the case, stuff that is compiled to an object file, and then linked
to the main, cannot be optimised quite as well as when the whole project
is built as a single entity.
A 'caveat'.

I'm assuming here that be 'external' you mean something that is #EXPORTed
and #IMPORTED into the main project. If the file is just #INCLUDE'd then
this is not 'external', but part of the main project.

As a further comment, it probably will not be stored at all. It'll just be
coded directly into the assembler. It takes just a single instruction to
code a int8 into a value. Just two instructions to code an int16. Storing
it and then retrieving it will involve a lot of code. So the compiler will
just encode it directly into the assembler as needed.
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