Write a C program that does the following:
You'll create the project the same way you create an assembly project, but under "Project templates and examples" you'll select "Empty project (with main.c)". The shortcut to build is still
Ctrl+B. The shortcut to debug is still
There's a good chance you'll run into a warning that says "variable XXXX was set but never used".
The compiler is seeing that you've created a variable and potentially set it to different values, but never tested the value or assigned it to another variable. As far as the compiler is concerned, this code is useless - and it will delete it upon compilation. It views this as an improvement - your program now does the same thing with less code.
Usually, this is the behavior we want. In learning situations like this, we want to keep the compiler from making these sorts of optimizations. There are two ways we can accomplish this.
volatilemodifier to the variables it's optimizing out. This tells the compiler that this varibale could be modified outside of the given code and not to optimize it away.
When programming in C, you'll want to monitor variables when you're debuggig. If you don't have a variables tab, go to View -> Variables. Now, a list of your program variables should be visible.
Sometimes it useful to look at variables in different bases. Maybe you want to see the value of a
char as an ASCII character or as a hex value. To change the base your variable is shown in, right-click on the variables, select Number Format and choose a new format.