The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 C functions across c files
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

peter.cook

UK
356 Posts

Posted - 01/28/2004 :  6:12:20 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

Probably displaying my lack of programming expertise here ...but how do I make a function in one C file usable in another C file? The particular case would be two C files attached to a project ot one attached and one in the client folder.

Thanks in advance,

Cheers,

Pete

cpyang

USA
1406 Posts

Posted - 01/28/2004 :  6:31:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You will need to create a header file and prototype the functions that are going to be shared, like

my_share.h

bool my_func(int nVal = 0);

my_share.c


bool my_func(int nVal)// = 0);
{
// actual codes
return true;
}


Alternatively, a better approach would be to create a class and have everything in a single header file. You can find one such example in

OriginC\System\Profiler.h

Since all the member functions are implemented inside the class, then you can just include this in any file that you will need to use this class. For example,

myTest.h


class myTest
{
myTest() // constructor
{
m_str = "Hello world\n";
}
public:
void DoSomething()
{
printf(m_str);
}
private:
string m_str;
};




then in one of your C file, then just


#include <origin.h>
#include "myTest.h" // header in same path as c file

void test()
{
myTest tt;

tt.DoSomething();
}





CP




Edited by - cpyang on 01/28/2004 11:10:12 PM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000