How do I use Perl's Inline::C?
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.
- 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.
try:
use Inline 'C';
print "9 + 16 = ", add(9, 16), "\n";
print "9 - 16 = ", subtract(9, 16), "\n";
__END__
__C__
int add(int x, int y) {
return x + y;
}
int subtract(int x, int y) {
return x - y;
}
精彩评论