Page 1 of 1

C issue or Keil issue (or my issue)

Posted: Tue Dec 24, 2013 12:27 am
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!

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

Posted: Tue Dec 24, 2013 8:34 am
by Giovanni
Optimizations, the skipped code does nothing or is optimized out.

Giovanni

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

Posted: Tue Dec 24, 2013 11:55 am
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

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

Posted: Tue Dec 24, 2013 10:36 pm
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

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

Posted: Tue Dec 24, 2013 10:48 pm
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.

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

Posted: Wed Dec 25, 2013 9:36 am
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