Solved

Global variables

Posted on 1998-07-22
2
267 Views
Last Modified: 2010-04-15
I have the following declaration in the header file of my project. This header file is included in every source file of the project. At one point in my main routine, I set this pointer to an address. After that, I start a series of threads that use the pointer. The problem is, some of the routines I call don't show the value I set prior to calling them but instead show NULL (the pointer's compile time value). What's wrong?

...
static struct CONNLIST *pProcessList = NULL;
...
0
Comment
Question by:flfmdll
2 Comments
 
LVL 5

Accepted Solution

by:
yonat earned 20 total points
ID: 1251781
"static" means file scope. So there is a separate pProcessList for each file that #includes this header. Replace "static" with "extern" in the header:
    extern struct CONNLIST *pProcessList;
and define the variable in just *one* of your .c files:
    struct CONNLIST *pProcessList = NULL;

0
 

Author Comment

by:flfmdll
ID: 1251782
Thank you. That works just fine. My excuse: it's been a very long time since I have used global variables.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now