Board index » delphi » using C in [Free]Pascal and vice versa

using C in [Free]Pascal and vice versa

Hi, All!

I have made a simple CGI program using some examples in web and in Free
Pascal documentation:

typec.c: (compiled using -c)

#include <stdio.h>

void typec(void);

void typec(void) {
        puts("This is printed using C function<BR>");
        fflush( stdout );

Quote
}

usec.pas:

Program usec;

{$linklib c}

Procedure typec; cdecl; external;

{$L typec.o}

begin

writeln ('Content-type: text/html');
writeln;
writeln('<HTML><BODY>');
writeln('This line is written in Pascal<BR>');
typec();
writeln('</BODY></HTML>');

end.

I have managed to link them both statically or dynamically (made .so file
from the typec). I am now interested how could I do this the other way
round, that means using my pascal units in C?

Also how could I use C classes in my pascal program? That means both
methods and variables... This is very importnant since I am trying to
program some sophisticated CGI applications that use libraries developed
in C++ by other people.

Imot Algma

 

Re:using C in [Free]Pascal and vice versa


Quote
In article <20030217132926.S73259-100...@vega.et.ee>, Imot Algma wrote:
> I have made a simple CGI program using some examples in web and in Free
> Pascal documentation:

y> writeln ('Content-type: text/html');

Quote
> writeln;
> writeln('<HTML><BODY>');
> writeln('This line is written in Pascal<BR>');
> typec();
> writeln('</BODY></HTML>');

> end.

> I have managed to link them both statically or dynamically (made .so file
> from the typec). I am now interested how could I do this the other way
> round, that means using my pascal units in C?

Don't know this atm.

Quote
> Also how could I use C classes in my pascal program?

C doesn't have classes.

Quote
> That means both methods and variables... This is very importnant since I
> am trying to program some sophisticated CGI applications that use
> libraries developed in C++ by other people.

This is not possible at the moment. C++ has a totally different object model
(classes and exceptions) than FPC. It would require a lot of
in-compiler-handling that is currently not implemented.

Workaround would be to make small plain C wrappers around the C++ objects, and use
them from FPC.

Other Threads