cancel
Showing results for 
Search instead for 
Did you mean: 

How to make a variable float to const float

methee_c
Associate III

Dear All,

I compile a program with cube ide and would like to know how the float variable is const float.

sample is. 

float a

const float  b

b = a;

BR,

Methee

1 ACCEPTED SOLUTION

Accepted Solutions

And I can't edit or pull code from a screen shot/bitmap.

Make a structure you're configuration items live in.

Create routines to read, write and validate this structure you can place in FLASH or EEPROM

FOO foo = { 0 };

void InitFoo(FOO *foo, EEPROM *eeprom)
{
...
  foo->donkeys = 12;
  foo->freqHz = eeprom->freqHz;
  foo->speedRPM = eeprom->speedRPM;  
...
}

 

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

View solution in original post

12 REPLIES 12
TDK
Guru

Const (constant) variables cannot be changed after they are initialized. This means you can and must initialize them only once.

It's a compiler flag more than anything that lets the compiler know that variable won't be changing and it can optimize things as if that variable will always be the same value.

If you feel a post has answered your question, please click "Accept as Solution".

Dear TDK,

You can help me for this solution?

float a =10;

const float  b=a;

BR, 

Methee

 

That code is valid and will compile just fine. What help is needed?

If you feel a post has answered your question, please click "Accept as Solution".

To what end?

const float b = 10.0f; 

Or pass it to a function that has const float x as a parameter?

The optimizer should try to fold constant values, perhaps use define?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

Dear Tesla DeLorean,

 

I need to read data from eeprom for change information in parameters of MotorControl Workbench 6.2.0 project.

But function parameters need to be const float or #define only.

Please help advise.

const float.jpg

 

BR,

Methee

That is not a function, but a structure initialization. You need to learn the C programming language first before trying to deal with complex software development.

The compiler can't initialize the structure with a variable.

You should start with an empty structure, and write a subroutine to do the initial fill from your EEPROM, or whatever.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

 

 

I can use it for Aruino ide but cube ide is very difficult to use. Can you make an inverter to sell if you are good at it? It didn't help me at all. It's better not to answer.

I'm just stuck here. Otherwise, I have no problem. Let's try to find another way. It doesn't seem to help me at all.