[advanced programming] please find an error in source code
Posted: Sat Apr 30, 2011 4:06 pm
Hello!
I am trying to find an error in source code of simple Content Library application. Maybe somebody else would see what causes the problem.
Here is the source code, compilation script and working executables of a simple Test application:
http://www.2shared.com/file/V-loZWGm/test.html
This app injects code for catching remote control buttons and blocks MUTE button as example task. Nothing more.
Now. Let's look at button_pressed() function in test_main.c file:
Then try to remove (or comment) the line with "unused = key;" command and recompile (using make.sh script). You'll see that test application is not working anymore. It will hang just after beeing loaded.
Now it is time to ask one simple question: WHY?
In my opinion, a variable called "unused" here shoud not have any influence on anything. But maybe the problem lays in a junction of high-level code and CPU/low-level-code (calling conventions, stack, alignment etc.) ??? Maybe I should use any additional compiler or linker directives? Please help me to understand what is going on.
I am trying to find an error in source code of simple Content Library application. Maybe somebody else would see what causes the problem.
Here is the source code, compilation script and working executables of a simple Test application:
http://www.2shared.com/file/V-loZWGm/test.html
This app injects code for catching remote control buttons and blocks MUTE button as example task. Nothing more.
Now. Let's look at button_pressed() function in test_main.c file:
Code: Select all
int unused;
// function called when a button is pressed
static int button_pressed(int key) __attribute__ ((noinline));
static int button_pressed(int key)
{
if (key == KEY_MUTE) key = KEY_NOTHING; // example function: block MUTE button
unused = key; // >>>>>> WITHOUT THIS IT CRASHES <<<<<<<< WHY? (Try to remove this line, recompile and see by yourself)
return(key);
}
Now it is time to ask one simple question: WHY?
In my opinion, a variable called "unused" here shoud not have any influence on anything. But maybe the problem lays in a junction of high-level code and CPU/low-level-code (calling conventions, stack, alignment etc.) ??? Maybe I should use any additional compiler or linker directives? Please help me to understand what is going on.
