LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: graydream

说说C语言的现状把?

[复制链接]
发表于 2005-8-19 09:59:27 | 显示全部楼层
出入栈并不意味着没有被直接嵌在被调用的函数里阿。我看的汇编代码inline的确是被嵌进去了,但是参数仍然是用栈的。
回复 支持 反对

使用道具 举报

发表于 2005-8-19 11:14:11 | 显示全部楼层
The most recent C standard is C99
C++ is too complex, life is short, and I am weak, so never bothered to learn it. maybe that's the only way to raise the salary of C++ programmers?


About linux kernel, C++ is too complex such that there are standard C++ runtime libary(libstdc++ on your system) to support the language, which runs in user space, now you want port it to kernel space(Hint: very rough environmen compared with user space)? Really brave,,,
回复 支持 反对

使用道具 举报

发表于 2005-8-19 16:19:14 | 显示全部楼层
SUN很早喊着要用JAVA写一个操作系统..最后也没写,是真的他写不出么?
windows,BSD,linux...都是C语言写的~C语言就象一把小刀,灵活多变,干什么都可以,虽然干大东西的时候费劲些~~~

C++,感觉还是适合GUI那些东西,非要拿到底层来,平台移植、还有他大多数的东西用不上
回复 支持 反对

使用道具 举报

发表于 2005-8-19 18:20:03 | 显示全部楼层
Post by gamedragon
出入栈并不意味着没有被直接嵌在被调用的函数里阿。我看的汇编代码inline的确是被嵌进去了,但是参数仍然是用栈的。

原话我改了
不知道是否让你误解了
你可不可以贴出来你的源代码
和你编译的命令

下面这段选自info gcc
Note that in C and Objective-C, unlike C++, the `inline' keyword does not affect the linkage of the function.
            
....

When a function is both inline and `static', if all calls to the
function are integrated into the caller, and the function's address is never used, then the function's own assembler code is never referenced. In this case, GCC does not actually output assembler code for the function, unless you specify the option `-fkeep-inline-functions'. Some calls cannot be integrated for various reasons (in particular, calls that precede the function's definition cannot be integrated, and neither can recursive calls within the definition).  If there is a non integrated call, then the function is compiled to assembler code as usual.  The function must also be compiled as usual if the program
refers to its address, because that can't be inlined.

When an inline function is not `static', th  en the compiler must assume that there may be calls from other source files; since a global symbol can be defined only once in any program, the function must not be defined in the other source files, so the calls therein cannot be integrated.  Therefore, a non-`static' inline function is always compiled on its own in the usual fashion.

我想你所预见的效果恐怕是static inline的效果吧
回复 支持 反对

使用道具 举报

发表于 2005-8-19 19:13:42 | 显示全部楼层
如果不加static,inline函数代码在编译生成的代码中仍然保留;如果加了static,这段代码就被去掉了。
刚才用gcc试了几段inline代码,加上-O1参数后,的确没有出现栈操作,而且优化的确实让人看起来绕了个弯。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-20 20:17:08 | 显示全部楼层
多谢各位大侠们,再问个问题阿:

关于C的面向对象几乎找不到书,那里有比较多的资料?

偶以前从来没注意过宏,听了各位的说法话才意识到这个缺陷,不过也没有发现哪些书详细讲宏的,推荐一下?
回复 支持 反对

使用道具 举报

发表于 2005-8-20 20:45:18 | 显示全部楼层
Post by graydream
多谢各位大侠们,再问个问题阿:

关于C的面向对象几乎找不到书,那里有比较多的资料?

偶以前从来没注意过宏,听了各位的说法话才意识到这个缺陷,不过也没有发现哪些书详细讲宏的,推荐一下?


看内核的源代码
回复 支持 反对

使用道具 举报

发表于 2005-8-21 22:02:11 | 显示全部楼层
面向对象的其实不是语言本身,而是一个哲学方面的问题(请允许我这样说),其实 C 也可以 OO 的。

C 我想不会淘汰的,正如汇编一样,涉及到具体平台的效率问题,底层工具往往事半功倍。
回复 支持 反对

使用道具 举报

发表于 2005-8-21 23:29:59 | 显示全部楼层
用C写OS的原因是因为完全用汇编太麻烦了。OS要对硬件直接控制,要追求尽量高的执行效率,尽量小的代码,所以用越底层的语言越好。理论上如此,可是如果直接用汇编,那么首先移殖性几乎为0,而且写起来也会成为一个极度痛苦的工作。所以用比汇编高级的C是必然的选择。

如果用C++,虽然代码写起来更容易,但是Linus本人说过(原文记不清了)“曾经试过用C++写Linux内核,但实践后才发现,任何一种试图封装内存操作或是底层操作的语言都不适合用来写操作系统”

不同封装级别的语言应该用在不同的场合。用汇编写Office类软件就不合适;用脚本语言来实现Office软件的插件就是较理想的选择。根据需要来选择语言,这就是基本的原则

最后说一下,即使是熟练的C++程序员,写出的代码的执行效率和资源占用也还是没有办法和熟练的C程序员写出的代码相比,虽然开发效率可能更高一下。鱼肉和熊掌总是不能兼得的

个人观点而已,欢迎指教
回复 支持 反对

使用道具 举报

发表于 2005-8-22 17:14:29 | 显示全部楼层
获益匪浅
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表