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
 Origin C function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

a.abc.b35

175 Posts

Posted - 01/27/2011 :  11:04:12 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
This is very elementary I guess. I have written a few origin C programs which have the same function within their body. Now if I have the same name for them in two separate programs, it gives me an error during compilation saying the function already has a body as that program was already compiled. At present I rename the functions, say if the function name in one program is myfunction than in the next program , i shall rename it to myfunction1. But can anyone tell me how I can do it without ever needing to change the name of the functions ? Can I make a separate file for the functions (like in C or C++) and call the function from there for all the programs ? Please help. I hope the question is clear.

AB

Penn

China
644 Posts

Posted - 01/27/2011 :  9:17:56 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi AB,

Commonly, a function you defined in Origin C can be used as a LabTalk command, which can run in Command Window, Script Window, etc, so the function name should be unique.

If you just want to used the function in its defined file, you can use the static function. In this way, the same function name can be used in different file. However, you cannot use this function as a command.
For example:

In test1.c file, there is a function defined as below, which can only be called by the other function defined in test1.c file.

static void test()
{
	out_str("test in test1.c");
}

In test2.c file, you can also defined a static function named test for other functions.

static void test()
{
	out_str("test in test2.c");
}

However, when you try to run command test in Command Window, error message is "#Command Error!", that is to say the function test cannot be run as a command.

Penn

Edited by - Penn on 01/28/2011 04:54:29 AM
Go to Top of Page

a.abc.b35

175 Posts

Posted - 02/02/2011 :  4:27:56 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you Penn. :-)

AB
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