我如何使用Perl的Inline :: C?

Sen*_*mar 2 perl inline

我有一段这样的代码(Perl文件):

print "9 + 16 = ", add(9, 16), "\n";
print "9 - 16 = ", subtract(9, 16), "\n";
Run Code Online (Sandbox Code Playgroud)

C代码也是,

#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;
} 
Run Code Online (Sandbox Code Playgroud)

如何使用perl运行此C代码Inline::C?我尝试过,但我并没有完全得到.

Nik*_*ain 8

  • 看一下 Inline::C-Cookbook- Inline C Recipes的聚宝盆,你会得到很多使用Inline with C例子.
  • 请参阅Inline- 使用其他编程语言编写Perl子例程,您将了解如何使用Inline,您也将获得C示例.


cod*_*ict 5

尝试:

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;
} 
Run Code Online (Sandbox Code Playgroud)