473,766 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"C vs java"

49 2904
aa*****@gmail.c om wrote:
Hi all,

See:- http://www.cs.princeton.edu/introcs/faq/c2java.html
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 "implementa tion 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
Jun 27 '08 #2
>
See:- http://www.cs.princeton.edu/introcs/faq/c2java.html
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
Jun 27 '08 #3
aa*****@gmail.c om said:
Hi all,

See:- http://www.cs.princeton.edu/introcs/faq/c2java.html
The first obvious error is the confusion of implementations with the
language proper, in the "compilatio n" 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\0x y"; 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 "polymorphi sm" 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 "inheritanc e" as "inheritenc e", 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 "overloadin g" 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
Jun 27 '08 #4
Richard Heathfield <rj*@see.sig.in validwrites:
>aa*****@gmail. com said:
>See:- http://www.cs.princeton.edu/introcs/faq/c2java.html
[snip]
>If one is to attack a language, one had better start by learning it.

I didn't see any attempt to attack either language;
I saw an attempt to summarize differences at a level suitable for
undergraduate students.

--
Chris.
Jun 27 '08 #5
Chris McDonald said:
Richard Heathfield <rj*@see.sig.in validwrites:
>>aa*****@gmail .com said:
>>See:- http://www.cs.princeton.edu/introcs/faq/c2java.html

[snip]
>>If one is to attack a language, one had better start by learning it.


I didn't see any attempt to attack either language;
The biggest clue, for me, was in this row:

graphics | use external libraries | Java library support, use our
| standard drawing library

The "our" suggested partisanship.
I saw an attempt to summarize differences at a level suitable for
undergraduate students.
Surely even undergraduate students deserve *accurate* information?

--
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
Jun 27 '08 #6
Richard Heathfield <rj*@see.sig.in validwrites:
>Chris McDonald said:
>Richard Heathfield <rj*@see.sig.in validwrites:
>>>aa*****@gmai l.com said:
>>>See:- http://www.cs.princeton.edu/introcs/faq/c2java.html

[snip]
>>>If one is to attack a language, one had better start by learning it.


I didn't see any attempt to attack either language;
>The biggest clue, for me, was in this row:
>graphics | use external libraries | Java library support, use our
| standard drawing library
>The "our" suggested partisanship.

Wow! you must live in, or seek, a very confrontational world if you
read partisanship for one as an attack on the "other".

Surely it's clear that a standard drawing library is/was provided for
Java, but no equivalent *provided* for C.
That's far from an attack.

>I saw an attempt to summarize differences at a level suitable for
undergraduat e students.
>Surely even undergraduate students deserve *accurate* information?
Agreed.

--
Chris.
Jun 27 '08 #7
In article <HO************ *************** ***@bt.com>,
Richard Heathfield <rj*@see.sig.in validwrote:
[lots of complaints]

Many of your supposed errors are a result of interpreting words as if
they meant what the C standard means by them. Obviously when comparing
languages you have to use words in a more general sense.

For example, when it says that you declare constants using #define,
this is perfectly true if you interpret it as "how do you accomplish
in C the task that would typically be described as declaring a
constant". The fact that you can't do this with a real C declaration
is a deficiency of C, not of the comparison.

-- Richard
--
:wq
Jun 27 '08 #8
Richard Tobin said:
In article <HO************ *************** ***@bt.com>,
Richard Heathfield <rj*@see.sig.in validwrote:
[lots of complaints]

Many of your supposed errors are a result of interpreting words as if
they meant what the C standard means by them.
Right. This is, after all, comp.lang.c, yes?
Obviously when comparing
languages you have to use words in a more general sense.
In which case you also have to move the discussion to a group where those
words won't be misinterpreted as having a more specific sense - i.e. not
comp.lang.c. My review was based on the theme of the newsgroup in which
the URL was posted.

<snip>

--
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
Jun 27 '08 #9
In article <hO************ *************** ***@bt.com>,
Richard Heathfield <rj*@see.sig.in validwrote:
>Obviously when comparing
languages you have to use words in a more general sense.
>In which case you also have to move the discussion to a group where those
words won't be misinterpreted as having a more specific sense - i.e. not
comp.lang.c. My review was based on the theme of the newsgroup in which
the URL was posted.
Frankly, that's just silly. If every newsgroup insists on pretending
things are in their own idiosyncratic terminology, even when they're
obviously not, how can we possibly have conversations? Do we have to
create a newsgroup for every possible combination of topics? Surely
it makes perfect sense to draw the attention of people in comp.lang.c
to a comparison of Java and C.

And it's disingenuous of you to suggest that the document will be
misinterpreted in comp.lang.c. It will only be misinterpreted by a
very few comp.lang.c readers, and they will be doing it deliberately.

-- Richard
--
:wq
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
20155
by: dmstn | last post by:
Is it possible to add those options in Notepad ++ ? Your help would be appreciated very much. Thanks in advance.
4
2704
by: devgupta01 | last post by:
Hi all, I have simple program- "HelloWorld.java" to run at eclipse. Java Version 1.4.2 Eclipse Version 3.2 class HelloWorld { public static void main(String aa) {
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.