Global variables 
Author Message
 Global variables

This must be a no brainer for everyone else.

a.How do I define global variables in C?
b.How do I define a global variable which is a pointer to a function in C?
   such as
   void *(foo)()

TIA.

--



Thu, 25 Apr 2002 03:00:00 GMT  
 Global variables

Quote:

> a.How do I define global variables in C?

Just define a variable outside any function block.

    int x; /* x is an external */

    void f(void)
    {
        int t = x; /* refers to external x */

        /* ... */
    }

Quote:
> b.How do I define a global variable which is a pointer to a function
> in C?
>    such as
>    void *(foo)()

Just as you would define a pointer to a function as a local (automatic)
variable:

     void (*foo)(void); /* pointer to function returning void and
                           taking no arguments */

--

 Alcyone Systems | irc maxxon (efnet) | web http://www.alcyone.com/max/
    San Jose, CA | languages en, eo | icbm 37 20 07 N 121 53 38 W
             USA | 420 days and counting | &tSftDotIotE
 __
/  \ Human love is often but the encounter of two weaknesses.
\__/ Francois Mauriac
--



Sat, 27 Apr 2002 03:00:00 GMT  
 Global variables

Quote:

>This must be a no brainer for everyone else.

>a.How do I define global variables in C?

Global variables are declared outside all funclions and struct
declarations.
However in most programs you don't need to use global variables.

Quote:
>b.How do I define a global variable which is a pointer to a function in C?
>   such as
>   void *(foo)()

void (*foo)(); /* pointer to a function taking an unspecfied number of
arguments and returning void */

Quote:

>TIA.

>--


Bart v Ingen Schenau
--



Sat, 27 Apr 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Global variable or not global variable

2. Uninitialized global data (was Re: Global variables)

3. static local variables vs global variables

4. Variables & Global Variables

5. global variables and external variables?

6. Why is not possible to assign a global variable to another global variable..?

7. Global variable

8. global variables

9. global variable

10. Regarding locks and global variables

11. Declaring Global Variable accessable with in the application.

12. Problem with global variables

 

 
Powered by phpBB® Forum Software