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
 accesing user-defined function in different c-fil
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

5*10

Germany
Posts

Posted - 09/29/2011 :  06:20:55 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 8.5 SR1
Operating System:Win XP

Dear all,

even that I put some effort in finding the answer to my question, I finally decided to post it here.

Is it possible to access a userdefined function which is located and definded in one originc-file from another function which is not within the same file?

Do I have to load the other c-file at the beginning of the current c-file?

Thanks

Daniel

Penn

China
644 Posts

Posted - 09/29/2011 :  10:47:17 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Daniel,

Here, suppose you want to use the function A in file a.c to call the function B in file b.c, you need to add the declaration of function B into the file a.c, or you can create a header file, and add the declaration of function B into this header file, and then include this header file in file a.c. Please note that, both a.c and b.c need to be loaded into the current workspace for compilation.

If you don't want to load b.c into the current workspace, you can try to use the FindFunction method.

Penn
Go to Top of Page

5*10

Germany
Posts

Posted - 10/07/2011 :  08:54:44 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Penn,

thx for the answer. I read and tested allready some days ago and it works perfectly. I used the FindFunction Option, because I didn't understand how to add the declaration. If one like; i would be glad to read what was meant by that.

In general it works with the FindFunction method.

Daniel
Go to Top of Page

Penn

China
644 Posts

Posted - 10/08/2011 :  01:35:09 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Daniel,

I suppose the function A in file a.c and function B in file b.c are as following, including the header file for the declaration of function B.

file a.c:

#include <Origin.h>

// need to include the header file, 
// which contains the declaration of function B
#include "b.h"

void A()
{
    // call function B, which is defined in b.c
    B();
}

file b.c:

#include <Origin.h>
void B()
{
    out_str("This is function B in file b.c");
}

and the header file should be (named b.h here):

void B();  // declaration of function B


If you don't want the header file, just add the declaration of function B in the file a.c, like:

#include <Origin.h>

void B();  // declaration of function B

void A()
{
    // call function B, which is defined in b.c
    B();
}


Penn
Go to Top of Page

5*10

Germany
Posts

Posted - 10/10/2011 :  06:46:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Penn,

thx a lot for the explanation. It works perfectly.
When I started with OriginC years ago I had this problem. There I copied the needed funtion all together and renamed them. As far as I define as well a body entrie I got in trouble with functions of the same name.
I never thought about the possibility to define/declare just the function.

Thx once again

5*10
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