Section 18.6 Bad Variable Names
Here is a really nasty example. Don’t ever write code with variable names like this! In the code, towards the right-hand side, comments are there to help you tell the scope of the variables and functions.
-
all: global scope - can be used anywhere (in main and functions)
-
main: scope is the main function, not known elsewhere
-
one: scope is function one
-
two: scope is function two
-
the function one cannot be called from the function two because of a conflict: in function two, there is a variable parameter that is called one and so this is what the function two will ’think of’ when it ’sees’ one.
-
So, function one can be called from main and it can be called from within itself, but it cannot be called from two.
Compile and run the code below in your own C environment.
#include <stdio.h>
#define MAX 10 // all
int one(int arg1, int arg2); // main, one
int two(int one, int arg1); // all
int main(void)
{
int i,j,k; // main
i = 2; j = 3;
k = one(i,j);
printf("One(%d, %d) = %d\n", i, j, k);
k = two(i,j);
printf("Two(%d, %d) = %d\n", i,j,k);
return(0);
}
int one(int arg1, int arg2) // main, one
{
int i; // one
i = two(arg1, arg2);
return(arg1 + i);
}
int two(int one, int arg2) // all
{
return(one*arg2+MAX);
}

