Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!utgpu!water!watmath!clyde!rutgers!cmcl2!brl-adm!adm!ADLER1%BRANDEIS.BITNET@wiscvm.wisc.EDU
From: ADLER1%BRANDEIS.BITNET@wiscvm.wisc.EDU
Newsgroups: comp.lang.c
Subject: scoping vs linking
Message-ID: <10575@brl-adm.ARPA>
Date: Sun, 29-Nov-87 14:41:10 EST
Article-I.D.: brl-adm.10575
Posted: Sun Nov 29 14:41:10 1987
Date-Received: Wed, 2-Dec-87 19:41:03 EST
Sender: news@brl-adm.ARPA
Lines: 58

I am very puzzled by the scoping rules in C. I've been looking at some
code which is spread out over several files and which compiles and runs
fine on various systems, including the SUN. In one file we have something
like:

main()
{ .... }

routine1()
{
        int klugec ;
        char **klugev ;

        routine2() ;
        .......

}


In another file we have

routine2()
{
    int i ;
    char *s ;

    ........

    klugev[i++] = s++ ;

    ........

}


Everything works fine. I tried moving routine2 into the first file
to make the file more self-contained and everything fell apart.
The compiler complained that it did not know what klugev is in
routine2. That is understandable, but I don't see what to do about it.
Is there a way to tell routine2 that klugev is the variable introduced
in routine1 ? The scoping rules don't seem to permit this. But then why
did the program work in the first place ? Apparently the linker is
compensating for what looks like a limitation on the expressive power
of C. While I am happy that the linker provides some recourse, at the
same time it bothers me to think that the linker must be taken into
account when writing a C program. The language C is at least the subject
of a proposed ANSI standard whereas I have no information about the
linker.

I am admittedly new at C and my naive comments could well be way off target.
I welcome your comments. I would be particularly interested in knowing how
to bring routine2 into the first file without substantially rewriting the
code.

Thank you.

Sincerely,
ADLER1@BRANDEIS.BITNET