添加将功能添加到结构中的功能? [英] Adding the ability to add functions into structures?

查看:59
本文介绍了添加将功能添加到结构中的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,结构对组变量很有用,因此您可以将

集合称为单个实体。收集变量和函数是否具有

能力是否有用?

问K& R说,C程序由变量组成存储输入和

函数来操作它们。


这会使C面向对象 - 它有多酷?

添加能否将功能封装在结构中是否有任何问题?

So structures are useful to group variables, so you can to refer to a
collection as a single entity. Wouldn''t it be useful to also have the
ability to collect variable and functions?

Ask K&R say, C programs consist of variables to store the input and
functions to manipulate them.

This would make C object-oriented - how cool would that be?

Are there any problems with adding the ability to have functions
encapsulated in structures?

推荐答案

在文章< 11 ********************** @ z14g2000cwz.googlegroups .com> ;,

Albert< al *****************@gmail.com>写道:
In article <11**********************@z14g2000cwz.googlegroups .com>,
Albert <al*****************@gmail.com> wrote:
因此,结构对组变量很有用,因此您可以将
集合称为单个实体。拥有收集变量和功能的能力是不是有用?
添加在结构中封装函数的能力是否有任何问题?
So structures are useful to group variables, so you can to refer to a
collection as a single entity. Wouldn''t it be useful to also have the
ability to collect variable and functions? Are there any problems with adding the ability to have functions
encapsulated in structures?




结构是数据,函数是代码。能够将

函数(而不是函数 - 指针)存储到结构中将需要使用数据变为可执行的机制。一些

架构(例如,哈佛架构)不能这样做。


在允许它的架构中,你将允许-all- of

您的数据是可执行的(在这种情况下,您拥有所有

经典堆栈溢出问题),否则您需要一个机制

-dynamically-表明特定的内存块是

可执行文件;这种动态方法的存在并非在任何特定系统上都是确定的。

-

它是否有任何可能的东西可以这么说,看,这是新的吗?它已经过时了,这已经是我们面前的了。 - Ecclesiastes



structures are data, functions are code. Having the ability to store
functions (instead of function -pointers-) into structures would
require mechanisms by which data become executable. Some
architectures (e.g., the Harvard architecture) cannot do that.

In architectures that do allow it, you would allow -all- of
your data to be executable (in which case you have all of the
classic stack overflow problems) or else you need a mechanism
to -dynamically- indicate that a particular block of memory is
executable; the existance of such a dynamic method is not at
all certain on any particular system.
--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes


Walter Roberson写道:
Walter Roberson wrote:
Albert< al **************** *@gmail.com>写道:
Albert <al*****************@gmail.com> wrote:
因此,结构对组变量很有用,因此您可以将集合称为单个实体。是否有能力收集变量和
函数?
So structures are useful to group variables, so you can to
refer to a collection as a single entity. Wouldn''t it be
useful to also have the ability to collect variable and
functions?


添加能力是否有任何问题?将
函数封装在结构中?
Are there any problems with adding the ability to have
functions encapsulated in structures?



结构是数据,函数是代码。能够将功能(而不是功能 - 指针)存储到结构中将需要数据变为可执行的机制。一些
架构(例如,哈佛架构)无法做到这一点。

在允许它的架构中,您可以允许所有的数据可执行(在在这种情况下你有所有经典的堆栈溢出问题)或者你需要一种机制来动态地指示一个特定的内存块是可执行的;在任何特定系统中,这种动态方法的存在都不是确定的。



structures are data, functions are code. Having the ability to
store functions (instead of function -pointers-) into structures
would require mechanisms by which data become executable. Some
architectures (e.g., the Harvard architecture) cannot do that.

In architectures that do allow it, you would allow -all- of your
data to be executable (in which case you have all of the classic
stack overflow problems) or else you need a mechanism to
-dynamically- indicate that a particular block of memory is
executable; the existance of such a dynamic method is not at all
certain on any particular system.




预测OP需要lisp。

-

"如果你想通过groups.google.com发布一个后续内容,请不要使用

破损的回复链接在文章的底部。点击

" show options"在文章的顶部,然后点击

回复在文章标题的底部。 - Keith Thompson

更多详情请见:< http://cfaj.freeshell.org/google/>



Methinks the OP wants lisp.

--
"If you want to post a followup via groups.google.com, don''t use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>


2005年12月30日17:12:33 -0800,Albert

< al ***************** @ gmail.com>在comp.lang.c中写道:
On 30 Dec 2005 17:12:33 -0800, "Albert"
<al*****************@gmail.com> wrote in comp.lang.c:
因此,结构对组变量很有用,因此您可以将
集合称为单个实体。具有收集变量和函数的能力是不是有用?

问K& R说,C程序包含存储输入的变量和
操作它们的功能。

这会使C面向对象 - 它会有多酷?

添加具有功能的能力是否有任何问题
封装在结构中?
So structures are useful to group variables, so you can to refer to a
collection as a single entity. Wouldn''t it be useful to also have the
ability to collect variable and functions?

Ask K&R say, C programs consist of variables to store the input and
functions to manipulate them.

This would make C object-oriented - how cool would that be?

Are there any problems with adding the ability to have functions
encapsulated in structures?




它已经完成了。他们在comp.lang.c ++中讨论它,在

大厅里。在comp.lang.java中,我也确定无论在哪个组中,它都是在微软的服务器上用于C#。


我知道我会为此受到抨击,但除了继承

这真的只是语法糖。您现在可以在C中编写对象

的程序。


一个完美的例子是FILE数据类型,声明为< stdio.h>。它有
有一个创建者,fopen(),一个析构函数,fclose(),以及你可以通过它的指针调用它的各种

方法,比如fprintf( ),
fscanf(),fread(),fwrite(),在它的成功创造和它的b $ b破坏之间。


-

Jack Klein

主页: http: //JK-Technology.Com

常见问题解答

comp.lang.c http://c-faq.com/

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt .comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html



It''s already been done. They discuss it in comp.lang.c++, down the
hall. And in comp.lang.java, and I''m sure also in whatever group it
is on Microsoft''s server that is devoted to C#.

I know I''ll get flamed for this, but with the exception of inheritance
this is really nothing but syntactical sugar. You can write object
oriented programs in C right now.

A perfect example is the FILE data type, declared an <stdio.h>. It
has a creator, fopen(), a destructor, fclose(), and all sorts of
methods you can invoke on it via its pointer, such as fprintf(),
fscanf(), fread(), fwrite(), between its successful creation and its
destruction.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


这篇关于添加将功能添加到结构中的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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