🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++.leda
Article #56

Re: Tricky question (I think)

#56
From: Heribert Dahms
Date: Fri, 25 Aug 1995 19:18
34 lines
1933 bytes
In <41gsif$1sa@eegradsrv.ee> adevasth@mtu.edu (Abhijit) writes:

: #include <iostream.h>
: main() {
:    void LU(int, float[][55], float[][55], float[][55], float[]);
:    void Display_lu(int, float[][55], float[][55], float[]); 
:    int n;
:    float A[55][55], L[55][55], U[55][55], d[55];
:    LU(n, L, A, U, d);
:    Display_lu(n, L, U, d);
: }
: void LU(int n, float L[][55], float A[][55], float U[][55], float d[]) {
:   cout << "HERE IN LU" << endl;
: }
: void Display_lu(int n, float L[][55], float U[][55], float d[]) {
:   cout <<"HERE IN DISPLAY" << endl;
: }
[...]

: But if I write the two prototypes above main() then it compiles and executes
: without any problem. So why do I have to make the functions global??
: Any help is appreciated.

You seem to confuse global and static:
Since you declared LU and Display_lu in the scope of the main body,
they are known inside the { } of main only.
You need to have file scope by putting it above the main as you said.
If you don't want them to appear global in the sense that external functions
in other files can link to them, you need to add the static keyword.

That's not LEDA specific, so please look again in a good C (or C++) book...


Bye, Heribert (dahms@ifk20.mach.uni-karlsruhe.de)
Technical Details
Message-ID: <41l7m3$ecb@nz12.rz.uni-karlsruhe.de>
Path: arc1-ca.pugleaf.net!rz.uni-karlsruhe.de!not-for-mail
References: <41gsif$1sa@eegradsrv.ee>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!rz.uni-karlsruhe.de!not-for-mail
From: DAHMS@ifk20.mach.uni-karlsruhe.de (Heribert Dahms)
Newsgroups: comp.lang.c++.leda
Subject: Re: Tricky question (I think)
Date: 25 Aug 1995 19:18:27 GMT
Organization: University of Karlsruhe, Germany (Dept. of Mechanical Engineering)
Distribution: world
Message-ID: <41l7m3$ecb@nz12.rz.uni-karlsruhe.de>
References: <41gsif$1sa@eegradsrv.ee>
NNTP-Posting-Host: ifk29.mach.uni-karlsruhe.de
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-News-Reader: VMS NEWS v1.25
In-Reply-To: adevasth@mtu.edu's message of 23 Aug 1995 23:44:15 -0400