C issue or Keil issue (or my issue)

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
eribla
Posts: 20
Joined: Fri Nov 29, 2013 1:10 am

C issue or Keil issue (or my issue)

Post by eribla »

Hi

my LCD display is working, but now I have a strange issue with variables and functions.

if you look a the attached KEIL listing (which I originally started to see why mybuf is not filled with the
content of myinput),
you see that line 187 and 191 are not at all seen and executed (the dark grey bar equals "executed").
halInit(), and chSysInit() are.

I have no idea why.
line 187 is jumped when doing single step and so is 191.

When I had the code for myfunc directly embedded in "main()", the mybuf = myinput would not execute.

I tested my full code with Visual C, where it works fine.

Also, BTW, if I do not declare "o" as static, the whole " int o...o++" will not be executed. (That still does not explain the myfunc issue but might be connected).

Thanks for all help.

Merry Christmas!
Attachments
keil.JPG
keil.JPG (30.39 KiB) Viewed 3327 times
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: C issue or Keil issue (or my issue)

Post by Giovanni »

Optimizations, the skipped code does nothing or is optimized out.

Giovanni
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: C issue or Keil issue (or my issue)

Post by Tectu »

Giovanni wrote:Optimizations, the skipped code does nothing or is optimized out.

Correct. The compiler does see that the variable is not used anywhere and therefore it's useless. You can change optimization levels in your Makefile. It's the -O flag. Simply change from -O3 to -O0


~ Tectu
eribla
Posts: 20
Joined: Fri Nov 29, 2013 1:10 am

Re: C issue or Keil issue (or my issue)

Post by eribla »

Hi guys,

merry Christmas..

I am amazed! So the compiler knows that a function is not effecting anything (since it's only a test and has no return value).

And the two times o++ will be combined....

You saved my sanity!

I guess at will not turn on optimization as long as the code is tested...

Thanks
eribla
Posts: 20
Joined: Fri Nov 29, 2013 1:10 am

Re: C issue or Keil issue (or my issue)

Post by eribla »

I was happy to early.

Unfortunately when setting optimization to "0" some other stuff does not work
like halInit(); in the example about never returns.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: C issue or Keil issue (or my issue)

Post by Giovanni »

Hi and Merry Christmas,

This can be caused by stack overflows or other similar problems, the stack usage increases when optimizations are disabled. You need to step into the code and see where it fails and how it fails. "Does not work" is too generic.

Giovanni
Post Reply