Getting rid of global 
Author Message
 Getting rid of global

>What is the best way to get rid of global variables in C?

Use local ones.

>Here is what I am using. Is there a better way or an easier way?

Obviously, since your code is not compilable.

>Instead of:
>int some_variable;

If this is actually a header to be included, make it
`extern int some_variable;'
and have the definition (`int some_variable;') in one of your *.c files.

>some_variable = 13;
>I am using:

Note all the compilation errors (BTW, lose the grotesque 21-line .sig):

>int some_variable(Boolean set, int new_value)

test.c:1: parse error before `set'

>   static the_variable;
>   static Boolean first_time = TRUE;

test.c: In function `some_variable':
test.c:4: parse error before `first_time'
test.c:4: warning: unused variable `Boolean'


>   if (set)

test.c:6: `set' undeclared (first use this function)
test.c:6: (Each undeclared identifier is reported only once
test.c:6: for each function it appears in.)

>   {
>      first_time = FALSE;

test.c:8: `first_time' undeclared (first use this function)
test.c:8: `FALSE' undeclared (first use this function)

>      return(the_variable = new_value);

test.c:9: `new_value' undeclared (first use this function)

>   }
>   else if (first_time)
>   {
>      first_time = FALSE;
>      return(the_variable = SOME_INITIAL_VALUE);

test.c:14: `SOME_INITIAL_VALUE' undeclared (first use this function)

>   }
>   else
>      return(the_variable);

test.c:18: warning: control reaches end of non-void function
test.c: At top level:
test.c:18: warning: ANSI C does not allow extra `;' outside of a function


* Honors Bridge Club, 115 E 57th, New York
* (212) 230-1230

Mon, 01 Feb 1999 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Getting rid of the web browser's toolbar

2. getting rid of C++ classes

3. getting rid of the DOS window in console application

4. Getting rid of leading whitesapce

5. Getting rid of the \n

6. Getting rid of the Carriage return

7. Getting rid of globals

8. Getting rid of CRLF i

9. Getting rid of CRLF in files

10. To All that have replied on Getting rid of if() statements

11. ADO DataGrid and getting values of the current row of the Data G rid

12. Getting Rid of Unnecessary .H files in Turbo C++


Powered by phpBB® Forum Software