Recent

Author Topic: inline c code  (Read 11958 times)

BeniBela

  • Hero Member
  • *****
  • Posts: 958
    • homepage
Re: inline c code
« Reply #15 on: June 19, 2015, 06:59:33 pm »
I vote for having inline c++ code

Much nicer language than c

Emil_Halim

  • New member
  • *
  • Posts: 9
Re: inline c code
« Reply #16 on: June 19, 2015, 07:26:49 pm »
I vote for having inline c++ code

Much nicer language than c

it is depend on FPC itself , can FBC link C++ Obj files.

i am working in FPCC which extracts c code from  pascal file.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12658
  • FPC developer.
Re: inline c code
« Reply #17 on: June 19, 2015, 07:33:48 pm »
I vote for having inline c++ code

Much nicer language than c

it is depend on FPC itself , can FBC link C++ Obj files.

If you integrate your own C++ compiler, you don't need to link with an external obj format, just pull the source through your own compiler.

And if you integrate a fully compatible C++ compiler that can link with the external obj format, that means duplicating GCC not only language wise but also internals and fileformats. Much, much harder

With C there is not much room for interpretation, but two different C++ compilers are generally not compatible
 
« Last Edit: June 21, 2015, 10:53:33 am by marcov »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: inline c code
« Reply #18 on: June 19, 2015, 07:37:12 pm »
It's not just an opinion, it's an objection! :P

your objection is nothing for me , and does not make any sens.

i will go on my way.
Feel free to do it, as long as you keep it away from FPC repository.

Emil_Halim

  • New member
  • *
  • Posts: 9
Re: inline c code
« Reply #19 on: June 19, 2015, 07:50:54 pm »

Feel free to do it, as long as you keep it away from FPC repository.

ok i have changed my mind , i will modify FPC itself and make my work.

rtusrghsdfhsfdhsdfhsfdhs

  • Full Member
  • ***
  • Posts: 162
Re: inline c code
« Reply #20 on: June 28, 2015, 03:57:03 pm »
This is quite interesting. Maybe it could be done with a GCC preprocessor. But does FPC has ways to intercept pre-post build events?

You would have to compile in memory I think. With this you could write a C kernel for OpenCL and run it with FPC.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12658
  • FPC developer.
Re: inline c code
« Reply #21 on: June 28, 2015, 04:05:58 pm »
This is quite interesting. Maybe it could be done with a GCC preprocessor. But does FPC has ways to intercept pre-post build events?

No, we prefer it fast :-)

rtusrghsdfhsfdhsdfhsfdhs

  • Full Member
  • ***
  • Posts: 162
Re: inline c code
« Reply #22 on: June 28, 2015, 04:13:47 pm »
Can you explain a bit more how fpcc works? Does it use some kind of file mapping? Oh and where to get it? 8-)

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: inline c code
« Reply #23 on: June 28, 2015, 06:18:59 pm »
Oh and where to get it? 8-)
as mentioned earlier:
it doesn't exist. Someone (you?) need to write it.

Can you explain a bit more how fpcc works? Does it use some kind of file mapping?

But it works very simple and straight forward.
here's the input file
Code: [Select]
program  MyPrg;

{$ASMMODE intel}

procedure GetTen;assembler;
asm
    mov eax, 10
    ret
end;


{$MODE C_code}
int strLen(char* p)
{
   char* s=p;
   while(*p++!=0);
   return s-p;
}

{$MODE FPC_code}

var
     Mystr : String;
     len    : longint;
Begin
     
     Mystr := "combing pascal and c like c++builder is good";
     len := strLen(@Mystr);
end.
FPCC parses the input pascal file and extracts all inline C out of it. Generating a .c file
Code: [Select]
#include ...whatever is needed...

int strLen(char* p)
{
   char* s=p;
   while(*p++!=0);
   return s-p;
}
Then it compiles the file via external C compiler into an object file, i.e. "unitname_cinline.o"

After than the remaining Pascal unit is prepared, replacing C-inline declarations with Pascal function headers (<- the biggest trick) and the proper object file linking
Code: [Select]
program  MyPrg;

{$ASMMODE intel}

procedure GetTen;assembler;
asm
    mov eax, 10
    ret
end;

function strLen(p: Pchar): integer; cdecl; external;
{$L unitname_cinline.o}

var
     Mystr : String;
     len    : longint;
Begin
     
     Mystr := "combing pascal and c like c++builder is good";
     len := strLen(@Mystr);
end.
Now this file is actually being passed to FPC for final complication/linking.
« Last Edit: June 28, 2015, 06:21:21 pm by skalogryz »

 

TinyPortal © 2005-2018