c++中调用ruby代码
#include < ruby.h > //
static int id_sum;
int Values[] = {5, 10 ,15,-1,20,0};
static VALUE wrap_sum(VALUE args)
{
VALUE * values = (VALUE *) args;
VALUE summer = values[0];
VALUE max = values[1];
return rb_funcall(summer,id_sum,1,max);
}
static VALUE protected_sum(VALUE summer, VALUE max)
{
int error; VALUE args[2];
VALUE result;
args[0] = summer;
args[1] = max;
result = rb_protect(wrap_sum,(VALUE)args, &error);
return error ? Qnil:result;
}
int main()
{
int value;
int *next = Values;
ruby_init();
ruby_init_loadpath();
ruby_script("embedded");
rb_require("sum.rb");
VALUE summer = rb_class_new_instance(0,0,rb_const_get(rb_cObject,rb_intern("Summer")));
id_sum = rb_intern("sum");
while (value = *next++)
{
VALUE result = protected_sum(summer,INT2NUM(value));
if (NIL_P(result))
{
printf("Sum to %d doesn't compute!\n",value);
}
else
printf("Sum to %d is %d\n",value,NUM2INT(result));
}
ruby_finalize();
}
相关文档:
系统环境:Windows 7
软件环境:Visual C++ 2008 SP1 +SQL Server 2005
本次目的:编写一个航空管理系统
这是数据库课程设计的成果,虽然成绩不佳,但是作为我用VC++ 以来编写的最大程序还是传到网上,以供参考。用VC++ 做数据库设计并不容易,但也不是不可能。以下是我的程序界面,后面 ......
(1)
数组名的内涵在于其指代实体是一种数据结构,这种数据结构就是数组;
(2)
数组名的外延在于其可以转换为指向其指代实体的指针,而且是一个指针常量;
(3)
指向数组的指针则是另外一种变量类型(在WIN32平台下,长度为4),仅仅意味着数组的存放地址
(4)
数组名作为函数形参时,在函数体内,其失去了本身的内涵 ......
c与c++ static函数的区别
本文转自:http://blog.csdn.net/lipps/archive/2007/05/18/1615419.aspx
static关键字是C, C++中都存在的关键字, 它主要有三种使用方式, 其中前两种只指在C语言中使用, 第三种在C++中使用(C,C++中具体细微操作不尽相同, 本文以C++为准).
(1)局部静态变量
(2)外部静态变 ......
在最近的一个关于LKML的讨论中,Linus给出了为什么不用C++来写Linux内核的理由:
"In fact, in Linux we did try C++ once already, back in 1992. It sucks. Trust me - writing kernel code in C++ is a BLOODY STUPID IDEA.
“事实上,我们曾经尝试过用C++来写,是在1992年的时候。很糟糕。相信我--用C++来写内核 ......