Forward referrence of static variables.

David W. Lauderback davel at cai.uucp
Wed Jan 2 19:42:13 AEST 1991


I think there is no "clean" solution to the problem I have but I wanted to test
my ability to post on the net so here is the problem:

I have some structures that make up a doublely linked list that I wish to
initialize.  The problem is I can't have two structures linked to each other.

Example:
--------------------
struct ll
{
        struct ll       *prev;  /* link to previous element */
        struct ll       *next;  /* link to next element */
        /* more fields ... */
};

/* Location 1 */

static struct ll	first = { 0,      &last /* , more data */ };
static struct ll	last  = { &first, 0     /* , more data */ };
--------------------

My solution is to add "extern struct ll last;" at location 1 and remove the
static's.  But I would much prefer to leave them static.  So back to the
original question, is there a way to forward referrence static variables?

I can think of two other unacceptable solutions.  One is to initialize these
in the code segment but this is harder to support and uses valuable space in my
particular application.  Another is that compilers will let you extern a
variable and then make it static, with a warning message.  However, this is not
portable so I can't use it.

					Thank in advance,
					David W. Lauderback
					uunet!cai!davel

PS. Please respond even if you don't have a comment.  I am trying to see how
    far this message gets.  I used distribution usa.  Should I have used a
    narrower distribution for this type of question?  Like ca maybe?

-- 
 -----------------------------------------------------------------------------
|     ###       #      ###      | David W. Lauderback (a.k.a. uunet!cai!davel)|
|    #   #     # #      #       |                                             |
|    #        #   #     #       |   (this space temporarily left blank)       |



More information about the Comp.lang.c mailing list