🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.c++.leda
2 messages
2 total messages Started by Abhijit Devasthale Thu, 24 Aug 1995 03:44
Tricky question (I think)
#55
Author: Abhijit Devasthale
Date: Thu, 24 Aug 1995 03:44
36 lines
1364 bytes
When I compile the following program using g++ I get the errors listed below
the program :
--------------------------------
#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;
}
----------------------------------
Errors:
ld: Undefined symbol
  _LU__FiPA55_fPA55_fPA55_fPf
  _Display_lu__FiPA55_fPA55_fPf
collect: ld returned 2 exit status
---------------------------------

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.

Abhijit.
Re: Tricky question (I think)
#56
Author: 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)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads