Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Perl's Inline::C?

Tags:

inline

perl

I have a piece of code like this (Perl file):

print "9 + 16 = ", add(9, 16), "\n";
print "9 - 16 = ", subtract(9, 16), "\n";

C code also,

#include<stdio.h>

main ()
{
 int x = 9;
 int y = 16;
 printf(" add() is %d\n", add(x,y));
 printf(" sub() is %d\n", subtract(x,y));
//  return 0; 
}
int add(int x, int y) 
{
 return x + y;
}

int subtract(int x, int y) 
{
 return x - y;
} 

How can I run this C code with perl using Inline::C? I tried but i am not exactly getting.

like image 408
Senthil kumar Avatar asked Oct 30 '25 05:10

Senthil kumar


1 Answers

  • Have a look at Inline::C-Cookbook - A Cornucopia of Inline C Recipes, you will get lot of examples using Inline with C.
  • See Inline - Write Perl subroutines in other programming languages, you will come to know how to use Inline and you will get C examples too.
like image 140
Nikhil Jain Avatar answered Nov 01 '25 01:11

Nikhil Jain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!