在运行时创建函数 [英] create function at runtime

查看:65
本文介绍了在运行时创建函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,我怎样才能在运行时声明/创建函数,类似于lisp中的
lambda。


谢谢


Mohan

解决方案

" invincible" <莫********** @ in.bosch.com>写道:

嗨朋友们,我怎样才能在运行时声明/创建函数,类似于lisp中的lambda。




你不能。反正不是在ISO C中;而不是在C的任何方言中我都不知道没有诉诸最毛茸茸的黑客。可能

涉及直接编写机器代码,除非你绝对必须,否则你真的不想做

。请注意,绝对必须包括

不能使用更适合这种语言的语言;在

捏,即使使用Clipper也会比修改自己的代码更好

空间。"


Richard


C语言没有设施。好吧,如果你想要创建这样的东西,你可以尝试一下这样的感觉

实际上你在运行时创建一个函数,但实际上你是

不...你接受输入并自己解析输入,如果这样的

语句就在那里::

printf(" hello world")

然后让它str =" hello World" ;;

和puts(str);


" DeltaOne" < SH ********** @ wipro.com>写道:

那么C语言没有设施。好吧,如果你想创建这样的东西,你可以尝试一下这样的感觉
实际上你在运行时创建一个函数,但实际上你没有...你...接受输入并自己解析输入,如果这样的语句是这样的话:
printf(" hello world")
然后使它成为str =" hello World" ;;
和puts(str);



< OT>

....或者您的进程将C文本写入文件,生成其他文件

编译和链接C的进程,然后动态加载生成的

共享对象到运行进程中,如果你的操作系统

支持它。

< / OT>


-

克里斯。


hi friends , how can I declare / create function during runtime similiar to
lambda in lisp.

thanks

Mohan

解决方案

"invincible" <mo**********@in.bosch.com> wrote:

hi friends , how can I declare / create function during runtime similiar to
lambda in lisp.



You cannot. Not in ISO C, anyway; and not in any dialect of C that I''m
aware of without resorting to the most hairy of hacks. It would probably
involve writing machine code directly, and you really don''t want to do
that unless you absolutely must. Note that "absolutely must" includes
"cannot possibly use a language which is better suited for this; at a
pinch, even using Clipper will be better than munging your own code
space."

Richard


Well there is no facility in C language for this. Well if you want to
create something like this you can try ony way that is giving a feel
that actually you are creating a function at run time but in actual you
dont...You take input and parse the input yourself and the if a
statement like this is there::
printf("hello world")
then make it str="hello World";
and puts(str);


"DeltaOne" <sh**********@wipro.com> writes:

Well there is no facility in C language for this. Well if you want to
create something like this you can try ony way that is giving a feel
that actually you are creating a function at run time but in actual you
dont...You take input and parse the input yourself and the if a
statement like this is there::
printf("hello world")
then make it str="hello World";
and puts(str);


<OT>
.... or your process writes the C text to a file, spawns other
processes to compile and link the C, then dynamically load the resulting
shared object into the running process, if your operating system
supports it.
</OT>

--
Chris.


这篇关于在运行时创建函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆