“C vs java” [英] "C vs java"

查看:77
本文介绍了“C vs java”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


请参阅: - http://www.cs.princeton.edu/introcs/faq/c2java.html

for C vs Java in number crunching

http://husnusensoy.blogspot.com/2006...crunching.html

Hi all,

See:- http://www.cs.princeton.edu/introcs/faq/c2java.html

for C vs Java in number crunching

http://husnusensoy.blogspot.com/2006...crunching.html

推荐答案

aa ***** @ gmail.com 写道:

大家好,


请参阅: - http: //www.cs.princeton.edu/introcs/faq/c2java.html



不错的清单,我会提到一些让我想到的事情。通过列表时,
。评论赞赏。


1)整数类型/浮点类型/字符类型

我会指定标准所要求的最小值,而不是

通常大小,其中通常可能意味着在x86系统上。


2)布尔类型

我猜页面是指C89,对吧?


3)数组声明

Malloc只是/ * one * /选项来定义数组。

另一种选择是将它们定义为固定长度,或者作为C99中的VLA 。


4)数据结构和数组的内存分配

为什么不只是写实现定义?


5)变量自动初始化

不保证绝对错误和误导。例如,全局和

静态变量/ *是* /初始化。自动变量不是。处理具有不同连接和存储的对象的这个

差异

持续时间并不会使初始化无法保证。


6)铸造

一切顺利?在编译时检测到一些铸造错误。


7)变量声明

见2)


Pietro Cerutti

Nice list, I would however mention a few things that go through my mind
while going through the list. Comments appreciated.

1) integer types / floating point types / character type
I would specify the minimum requested by the standard, instead of the
"usual" size, where "usual" probably means on x86 systems.

2) boolean type
I guess the page refers to C89, right?

3) array declarations
Malloc is just /*one*/ option to define arrays.
Another option is to defines them as fixed length, or as VLAs in C99.

4) memory allocation of data structures and arrays
why not just write "implementation defined"?

5) variable auto-initialization
"not guaranteed" is definitely wrong and misleading. E.g., global and
static variables /*are*/ initialized. Automatic variable aren''t. This
difference in treating objects with different linkage and storage
duration doesn''t make initialization "not guaranteed".

6) casting
"anything goes"? Some casting errors are detected at compile time.

7) variable declaration
see 2)

Pietro Cerutti



>

请参阅: - http://www.cs.princeton.edu/introcs/faq/c2java.html



嗯,我想知道编辑的意图是什么。

c2java.html ...将c程序转换为java?还是C程序员来自
Java程序员?

列表确实似乎是指C89,而Java与C99的比较

会有所不同很多要点。让我印象最深刻的是比较

的约定。这不是语言功能。该列表还建议

因为gcc是标准编译器(虽然在很多系统上确实如此,但实际上是
),
仍然是
,比较gcc由于

两种语言之间的差异,因此javac接口的界面几乎不会是b $ b。


阅读完列表后,我仍然不能

得到我认为最重要的主要差异(主要是

跟随

来自对象导向的不同支持级别

编程。)

为了说点积极的话,列表很好地反映了C和Java

已经

专为大多数不相交的观众设计,(但这让我怀疑

关于

a标题如c2java),根据列表可以做出决定

为了特定目的学习或使用b / b
,即使列表有偏见

朝向

Java。

因为焦油,可能是所有的批评都是过分的获得观众



此列表已编译为我不知道。


Szabolcs

Hmm, I wonder what the intention of the editors of this could be.
c2java.html ... to convert c programs to java? or C programmers to
Java programmers?
The list indeed seem to refer to C89, and a comparison of Java to C99
would differ in many points. What struck me most was the comparison
of conventions. That''s not a language feature. The list also suggests
as gcc was the standard compiler (although on many systems it is,
indeed),
still, comparing the gcc interface to the javac interface is hardly
due to
the differences of between two languages.

After reading the list, I still could not
get the main differences that I believed to be most important (mostly
following
from the different levels of support for object orientated
programming.)
To say something positive, the list nicely reflects that C and Java
have been
designed for mostly disjoint audiences, (But this makes me suspicious
about
a title like c2java), and based on the list one can make decisions
which
to learn or use for a specific purpose, even though the list is biased
towards
Java.
Could be that all criticism is undue, since the target audience for
which
this list has been compiled for is unknown to me.

Szabolcs


aa*****@gmail.com 说:

大家好,


见: - http://www.cs.princeton.edu/introcs/faq/c2java.html



第一个明显的错误是在编译中使用

语言正确实现的混淆。行。在以下三行的每个

中再次出现此错误。


次要:hello,world行没有显示hello,world。程序在
C或Java。


整数类型 row省略了char,short和unsigned类型。


浮点类型行省略长双。


for循环 row并没有展示for循环的全部功能。


数组声明行没有显示如何声明数组。相反,

它显示了如何为N个对象分配内存。 (奇怪的是,作者没有

只能获得正确的分配,但几乎可以*正常*正确。)


数组大小 row说数组不知道它们自己的长度,但实际上它可以通过sizeof arr / sizeof arr [0]来计算。


字符串行错误地表示字符串是''\0'' - 终止

字符数组。考虑:char foo [8] =" u\0v\0w\ xxy" ;;这不包含

一个字符串但是六个,并且它们都不是数组。此外,数组

本身不是''\0'' - 终止。这是''y'' - 终止了!


访问图书馆 row没有演示如何访问库。

它演示了如何包含标题。


访问库函数行显示两个代码片段,它们不能重合,就好像它们确实重合一样,并声明了函数和变量名称的全局
性质而没有明确说明什么他们

的意思是全球。是否变量是全球的取决于

你所说的全球是什么意思以及你所说的变量是什么意思而且对于

是否变量是自动限定的(请记住,在

函数中,自动限定是/ default /)。如果作者将

仅仅指向(a)包含在库中的函数和变量,并且

(b)对调用者可见 - 这似乎是合理的扣除 -

然后他应该明确这一点。


打印到标准输出 row显示示例代码,该代码写入默认为行缓冲的

流,而不会终止

行或刷新流。

格式化打印排是有意思的,因为它基本上说是

看看Java从C中偷走了什么。


从stdin读取行显示破坏的示例代码,无法检查读取的结果。


内存地址行没有说清楚引用如何与

指针不同。在我看来,引用/是/指针。任何

其他名称的玫瑰,以及所有这些。


按值传递 row表明非原始的非结构非指针

数据类型(例如联合)可能/不会/通过值传递,而当然

事实是,在C中,*所有*都是按值传递的。


次要的:访问数据结构 row使用术语分子,

在上下文中看起来很奇怪,因为没有任何数字被计算。


分配内存 row专注于malloc,不仅忽略calloc和

realloc,还忽略静态声明语法。


数据结构和数组的内存分配 row将

语言与实现混淆。


缓冲区溢出行似乎暗示崩溃与运行时

错误异常在某种程度上比使用段错误更可取,但是它没有明确为什么这是优选的b $ b 。


声明常量 row表明#define构成了一个

声明,它不会。


变量自动初始化 row表示,正如有人指出

elsethread,C根本没有做任何初始化保证,

而静态,外部和部分初始化的聚合对象所有

都有明确的保证初始化规则。


铸造 row说什么都行,这简直就错了。


多态性 row包含拼写错误。现在,我知道有点

infra dignitatis指出拼写错误,但这个是一个

拼写错误的继承作为继承,这表明作者没有读过很多关于OOP的内容,或者说他没有一个非常有效的内存。 。这些可能性都不是很令人放心。


次要的:超载对于像+,+,*等等运算符一样,行忽略了C'无可否认的

重载的例子。


"变量声明 row忽略了这样一个事实,即在

文件范围内声明的名称不是偶数/在一个块中,更不用说在一个开头了。


变量命名约定排是完全错误的。有程序员有很多

约定。

C语言规范,实现或类似的任何东西都没有强制要求单一约定。 (项目

经理,现在 - 这是一个不同的故事。如果只有他们都可以同意

一个会议......)


文件命名约定 row将语言与

实现甚至文件系统混淆!


回调行表示非全局行。函数不能用作

回调。当然,静态函数是一个反例。


可变数量的参数行提及varargs在C

栏下,但我不明白为什么。 C标准甚至没有提到这个

术语,如果没有定义,它实际上毫无意义。


退出并返回操作系统的值。 row提供了一个非常糟糕的退出调用

(值没有可移植的语义),并且没有提到从

main返回。


如果要攻击某种语言,最好先学习它。


-

Richard Heathfield< http:// www .cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

The first obvious error is the confusion of implementations with the
language proper, in the "compilation" row. This error occurs again in each
of the following three rows.

Minor nit: the "hello, world" row doesn''t show a "hello, world" program in
either C or Java.

The "integer types" row omits char, short, and unsigned types.

The "floating point types" row omits long double.

The "for loops" row doesn''t demonstrate the full power of the for loop.

The "array declarations" row doesn''t show how to declare an array. Instead,
it shows how to allocate memory for N objects. (Curiously, the author not
only gets the allocation right, but almost gets it *canonically* right.)

The "array size" row says that arrays don''t know their own length, but in
fact it is trivially calculable from sizeof arr / sizeof arr[0].

The "strings" row incorrectly says that a string is a ''\0''-terminated
character array. Consider: char foo[8] = "u\0v\0w\0xy"; this contains not
one string but six, and none of them is an array. Furthermore, the array
itself is not ''\0''-terminated. It is ''y''-terminated!

The "accessing a library" row does not demonstrate how to access a library.
It demonstrates how to include a header.

The "accessing a library function" row shows two code fragments that cannot
coincide as if they did coincide, and makes a claim about the "global"
nature of function and variable names without making it clear what they
mean by "global". Whether "variables" are "global" depends not only on
what you mean by "global" and what you mean by "variable" but also on
whether the "variables" are auto-qualified (and remember that, within a
function, auto qualification is the /default/). If the author is referring
solely to functions and variables that are (a) contained in a library and
(b) visible to the caller - and this seems like a reasonable deduction -
then he ought to make this explicit.

The "printing to standard output" row shows example code that writes to a
stream that is line-buffered by default, without either terminating the
line or flushing the stream.

The "formatted printing" row is interesting insofar as it basically says
"look what Java stole from C".

The "reading from stdin" row shows broken example code, which fails to
check the result of the read.

The "memory address" row doesn''t make it clear how a reference differs from
a pointer. It seems to me that a reference /is/ a pointer. A rose by any
other name, and all that.

The "pass-by-value" row suggests that non-primitive non-struct non-pointer
data types (e.g. unions) might /not/ be passed by value, whereas of course
the truth is that, in C, *everything* is passed by value.

Minor nit: the "accessing a data structure" row uses the term "numerator",
which seems rather strange in the context, as nothing is being numerated.

The "allocating memory" row focuses on malloc, ignoring not only calloc and
realloc but also static declaration syntax.

The "memory allocation of data structures and arrays" row confuses the
language with an implementation.

The "buffer overflow" row seems to suggest that crashing with a run-time
error exception is somehow preferable to crashing with a segfault, but it
isn''t made clear why this is preferable.

The "declaring constants" row suggests that #define constitutes a
declaration, which it doesn''t.

The "variable auto-initialization" row suggests, as someone has pointed out
elsethread, that C doesn''t make any initialisation guarantees at all,
whereas static, external, and partially-initialised aggregate objects all
have well-defined and guaranteed initialisation rules.

The "casting" row says "anything goes", which is simply wrong.

The "polymorphism" row contains a spelling error. Now, I know it''s a bit
infra dignitatis to point out spelling errors, but this one is a
misspelling of "inheritance" as "inheritence", which suggests either that
the author hasn''t read a great deal about OOP or that he doesn''t have a
very retentive memory. Neither of these possibilities is very reassuring.

Minor nit: the "overloading" row overlooks C''s admittedly minor examples of
overloading, on operators such as +, ++, *, and so on.

The "variable declaration" row overlooks the fact that names declared at
file scope are not even /in/ a block, let alone at the start of one.

The "variable naming conventions" row is simply wrong. There are as many
conventions as there are programmers. No single convention is mandated by
the C language spec, implementations, or anything of the kind. (Project
managers, now - that''s a different story. If only they could all agree on
one convention...)

The "file naming conventions" row confuses the language with the
implementation and even the file system!

The "callbacks" row suggests that "non-global" functions can''t be used as
callbacks. Of course, static functions are a counter-example.

The "variable number of arguments" row mentions "varargs" under the C
column, but I have no idea why. The C Standard doesn''t even mention this
term, and it is effectively meaningless without definition.

The "exit and return value to OS" row provides a very poor-style exit call
(value has no portable semantics), and fails to mention returning from
main.

If one is to attack a language, one had better start by learning it.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


这篇关于“C vs java”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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