box-o-sand/oldstuff/lcthw-remnants/ex22_main.c

73 lines
1.7 KiB
C
Raw Normal View History

2011-11-02 01:56:34 +00:00
#include "ex22.h"
#include "dbg.h"
const char *MY_NAME = "Zed A. Shaw";
void scope_demo(int count)
{
log_info("count is: %d", count);
if(count > 10) {
int count = 100; // BAD! BUGS!
log_info("count in this scope is %d", count);
}
log_info("count is at exit: %d", count);
count = 3000;
log_info("count after assign: %d", count);
}
int main(int argc, char *argv[])
{
// test out THE_AGE accessors
log_info("My name: %s, age: %d", MY_NAME, get_age());
set_age(100);
log_info("My age is now: %d", get_age());
int new_age = 44;
log_info("Setting age directly to %d", new_age);
int *age = get_age_pointer();
*age = new_age;
log_info("My age is now: %d", get_age());
2011-11-02 01:56:34 +00:00
// test out THE_SIZE extern
log_info("THE_SIZE is: %d", THE_SIZE);
print_size();
THE_SIZE = 9;
log_info("THE_SIZE is now: %d", THE_SIZE);
print_size();
// test the ratio function static
log_info("Ratio at first: %f", update_ratio(2.0));
log_info("Ratio again: %f", update_ratio(10.0));
log_info("Ratio once more: %f", update_ratio(300.0));
// accessing a function static
double *func_static_value = get_function_static(4.0);
log_info("get_function_static(4.0) = %.1f", *func_static_value);
double new_func_static_value = 8.0;
log_info("Setting the function static var directly to %.1f",
new_func_static_value);
*func_static_value = new_func_static_value;
log_info("get_function_static(4.0) = %.1f", *get_function_static(4.0));
2011-11-02 01:56:34 +00:00
// test the scope demo
int count = 4;
scope_demo(count);
scope_demo(count * 20);
log_info("count after calling scope_demo: %d", count);
return 0;
}