LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-12-2003, 11:20 AM   #1
chris.hicks
Member
 
Registered: Sep 2003
Location: Newcastle upon Tyne
Distribution: Red Hat 9
Posts: 42

Rep: Reputation: 15
GNU C calls GNU Pascal?


I am continuing producing lots of little examples in C. I am wanting to call a Pascal producedure from C. I have done this many times using Sun's SparcWorks.

My Pascal function is in the file pascalfunc.p which is
[
procedure helloworld;
begin
writeln("Hello world in Pascal");
end;
]


However, when I do the compile gpc -c pascalfunc.p I get error messages because the compiler seems to be expecting a full program.
[nmansys@mmme1 c_examples]$ gpc -c pascalfunc.p
pascalfunc.p:0: warning: missing program header
pascalfunc.p:5: syntax error at end of input

I would be grateful for any ideas. I will publish my C examples when I have finished them all.

Chris
 
Old 11-13-2003, 09:48 AM   #2
chris.hicks
Member
 
Registered: Sep 2003
Location: Newcastle upon Tyne
Distribution: Red Hat 9
Posts: 42

Original Poster
Rep: Reputation: 15
Problem solved

I have hunted round and found the answer to my problem. The example consists of pascalfunc.p (contains the Pascal procedure), externpascal.h, externpascal.c (which contains main and calls the procedure) and a Makefile. To be honest, I don't understand the _p_intialize(argc,argv,envp); or _p_finalize(); lines or the associated arguments, but it works! I would be grateful for an explanation from any gurus out there.

Chris
------------------------- files attached in [ ]

pascalfunc.p:
[
unit Foo;

interface

procedure Helloworld;
procedure Hello1;

implementation

procedure Helloworld;
begin
writeln("Hello world in Pascal");
end;

procedure Hello1;
begin
writeln("Hello1");
end;

end.
]

externpascal.h:
[
extern void Helloworld(void); /*function in pascalfunc.p */
extern void Hello1(void);
]

externpascal.c:
[
/*Calling external pascal functions in C (from pascalfunc.p) */

#include <stdio.h>
#include <string.h>
#include "externpascal.h" /*contains extern statement */
#include <gpc-in-c.h>

int main (int argc, char* *argv, char* *envp)
{
init_Foo();
_p_initialize (argc,argv,envp);
Helloworld();
Hello1();
_p_finalize ();
}
]

Makefile:
[
pascalextern : externpascal.c pascalfunc.o
gcc externpascal.c pascalfunc.o -o externpascal -lgpc -lm
pascalfunc.o : pascalfunc.p
gpc --automake -c pascalfunc.p
clean :
rm extern.o externalfunc.o
]
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GNU/Linux vs. GNU/OpenSolaris win32sux Linux - Software 5 11-27-2005 11:10 AM
newb question on GNU glibc-2.3.1 upgrade to GNU glibc-2.3.2 clindy528 Slackware 1 11-10-2005 07:49 AM
Debian GNU/kFreeBSD && Debian GNU/NetBSD Arnaud_B Debian 3 06-30-2005 11:39 PM
GNU Pascal calls GNU C chris.hicks Programming 0 11-13-2003 12:18 PM
GNU c++ Mikeoak83 Linux - Software 3 04-09-2003 04:47 AM


All times are GMT -5. The time now is 06:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration