pascal ?
Posted: Fri May 28, 2010 9:28 pm
I am just learning another language other then my standard c/c++ , asm compiled languages I know.
I am getting familar will fortran, and pascal.
My problem is I am trying to call pascal from c. I know pascal uses a right to left calling convention where the callee cleans the stack. That is why I am using stdcall and having a wrapper function reverse the function parameters the the pascal function.
My problem in getting this to work is from the pascal side of things the structure is
My problem is when I compile
errors are
What I think is the problem is that
in the testfunc.pas file creates a main entry point as does my c file.
So is their away to just declare function with no main part in a .pas file I don't know how to create .pas file that holds just functions/procedures all that I have seen on the internet is examples with the main in them.
So first off if anybody can fix this entry point issue that would be a great help.
error 2 is probably caused by a name mangleing thing I have read that pascal compiles their functions with a underscore infront of them ? Either way I don't know of a good way to fix this yet?
Like in asm on a windows machine I have to call a c function with an underscore in front of it but that is an easy fix just but the underscore on it. For pascal I don't know how to do the equivalent if that is the problem.
Here is my c code I am using the calling convention stdcall for my extern pascal function call from c program
Thanks for any help
I am getting familar will fortran, and pascal.
My problem is I am trying to call pascal from c. I know pascal uses a right to left calling convention where the callee cleans the stack. That is why I am using stdcall and having a wrapper function reverse the function parameters the the pascal function.
My problem in getting this to work is from the pascal side of things the structure is
Code: Select all
program testfunc (output);
function ADD_TWO ( value1, value2 : integer ) : integer;
begin
ADD_TWO := value1 + value2 ;
end;
begin;
{do nothing in here this is the equivalent of main in pascal}
end.
Code: Select all
gpc -c testfunc.pas (this gives me testfunc.o which is what it should)
gcc test.c testfunc.o ( this gives me 2 errors )
Code: Select all
testfunc.o: In function `main':
testfunc.pas:(.text+0x93): multiple definition of `main'
/tmp/cc9VGadq.o:test.c:(.text+0x0): first defined here
/tmp/cc9VGadq.o: In function `main':
test.c:(.text+0x2d): undefined reference to `ADD_TWO'
collect2: ld returned 1 exit status
Code: Select all
begin;
end.
So is their away to just declare function with no main part in a .pas file I don't know how to create .pas file that holds just functions/procedures all that I have seen on the internet is examples with the main in them.
So first off if anybody can fix this entry point issue that would be a great help.
error 2 is probably caused by a name mangleing thing I have read that pascal compiles their functions with a underscore infront of them ? Either way I don't know of a good way to fix this yet?
Like in asm on a windows machine I have to call a c function with an underscore in front of it but that is an easy fix just but the underscore on it. For pascal I don't know how to do the equivalent if that is the problem.
Here is my c code I am using the calling convention stdcall for my extern pascal function call from c program
Code: Select all
#include <stdio.h>
extern void __attribute__((stdcall)) ADD_TWO( int a , int b );
int main(int argc , char **argv) {
puts("Going to call Pascal!");
ADD_TWO( 1 , 2 ) ;
puts("Returned from Pascal!");
return 0;
}
Thanks for any help