LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-13-2005, 02:30 AM   #1
vdogvictor
Member
 
Registered: Feb 2004
Distribution: Arch
Posts: 498

Rep: Reputation: 31
Just How portable is C?


I'm going to be taking a programming class in the spring, either Java or C. I already have expereince with VB.NET and a small amount of java experience. When I look at C code i think "ick" (even though I don't understand most of it). Java just flows better to me.

The problem is C is much more versatile. The only thing java has on C is applets. But nobody writes kernels or device drivers in java, and rarely are non applet programs made in Java. So I think that it would be worth me learning C. Here is my question though:

Right now I am running a mac mini (no linux on it yet) and have no PC. I'd assume whatever C class I take would teach it in a windows centric way. So just how useful to me would this be if I want to primarily code for Mac OS and linux PPC/x64/x86? How OS/processor specific does C get?
 
Old 11-13-2005, 04:28 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,490

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
Quote:
The only thing java has on C is applets.
!!!
Look again ...

Quote:
rarely are non applet programs made in Java.
!!!
I would say the opposite, the number of applets written is certainly very very small compared to the number of java applications.

C and Java is not fully overlapping, low level programming still requires C or even assembly language, while C isn't able to generate portable web-applications or enterprise applications suitable for a J2EE application server.

That said, developing kernels and kernel modules is limited to a very small group of programmers, while a lot of the professional work done with java are web applications.

Last edited by jlliagre; 11-13-2005 at 05:26 AM.
 
Old 11-13-2005, 11:35 AM   #3
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,078

Rep: Reputation: 297Reputation: 297Reputation: 297
If you stick to ISO standard C, your programs will be source compatible accross about every platform in existence. Likewise you can use stuff from other standards such as POSIX and expect it to work on POSIX platforms etc.

And yes, Java is used for much more than for applets. Look at what all gets done with J2EE for instance. I use both Java and C -- they each have their own place in the world.
 
Old 11-13-2005, 12:17 PM   #4
makron
LQ Newbie
 
Registered: Nov 2005
Location: Germany
Distribution: Slackware
Posts: 5

Rep: Reputation: 0
well, i think the question is not "how portable is C" ... the question should be "how portable is your code" ... some people tend to use OS specific stuff that is not really necessary ... for example: there are people that open a file in windows with CreateFile (i think is the name of the function !?) and they are wondering why their code does not compile on another OS.

if you use portable toolkits, libraries and so on your code is also portable, so you may direct the problem of portability to the libraries and toolkits you use :-)

Last edited by makron; 11-13-2005 at 12:29 PM.
 
Old 11-13-2005, 03:50 PM   #5
vdogvictor
Member
 
Registered: Feb 2004
Distribution: Arch
Posts: 498

Original Poster
Rep: Reputation: 31
Thanks for all the replies!

sorry for underestimating java. I guess I should be asking how likely is it the C that is taught in college courses will be portable? I have no clue if they teach ISO or POSIX or whatever type of C.
 
Old 11-13-2005, 09:43 PM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,490

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
Neither do we, asking the college teachers/students would lead to a better answer.
 
Old 11-14-2005, 06:14 PM   #7
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 111Reputation: 111
If you make importable(?) calls only when there no other way not to, and seperate the portable from the importable portions, your code is at nearly maximum portability, and you only need to reimplement your minimal OS specific stuff. And there is a java discussion thread here.
 
Old 11-14-2005, 09:48 PM   #8
RandomLinuxNewb
Member
 
Registered: Oct 2003
Distribution: Slackware
Posts: 101

Rep: Reputation: 15
If your taking a computer science class then the code your write should be basic ISO C code. When I took my CSCI class all the work I did in class was on a Mac and all the work I did at home I did on a PC running linux. I didn't have any problems as the class didn't ever go into developing platform dependent code. Now if your taking an application development class then you maybe in some trouble as likely they will be teaching you to use Visual C++ and using MFC to develop for Windows and that is not portable code.
 
Old 11-15-2005, 01:20 AM   #9
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,490

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
Quote:
If you make importable(?)
it is "non portable" (importable means it can be imported)
Quote:
seperate
separate
Quote:
Also, use proper English so that it can be understood.
Everybody tries ...
 
Old 11-15-2005, 06:33 AM   #10
vdogvictor
Member
 
Registered: Feb 2004
Distribution: Arch
Posts: 498

Original Poster
Rep: Reputation: 31
alright thanks a lot, I think I'll be fine taking the class then. It's not an application development class, just an intro to programming.
 
Old 11-15-2005, 08:43 AM   #11
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 42
The CS track at Dartmouth College (hanover) is mostly java.

In terms of portability, java really does beat C. Yes, you can write hello world and maybe one or two levels up from that portably with C, but AFAIK all realisticly sized C applications that run on both windows and linux have a lot of conditional compilation, either through #ifdef's or makefiles. (Speaking of which, Makefiles don't port to windows all that well...)

That said, the C you learn in a class will probably be perfectly helpful on linux. You may not use exactly the same libraries (and completely different ones for guis)

If you care about kernels or device drivers, you don't have much choice. Similarly if you care about applets. In terms of a first language, Java pushes OO concepts on you where C doesn't (which is either good or bad) and C attempts to confuse you with pointers and memory management. If you already know OO, java will be easier. Otherwise maybe it's a wash.
 
Old 11-15-2005, 12:15 PM   #12
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 111Reputation: 111
My sig refers mostly to those who refuses to capitalize anything, writes how Yoda talks, and have every other word mispelled, not just the trickier ones. I think I was almost asleep when I posted that as well. For some reason "non portable" didn't sound right to me.

On topic, ISO C means that you have exactly the same classes for string, vector, map, set, etc... If you use those classes and methods, it is guaranteed to work on any platform.

As for your comments on C and Java, pointers are insanely powerful when you realize all the flexibility they can add to a program. Managing your own memory will also be much more efficient then having Java handle it for you, cause as a programmer, you should know exactly how the data flows. Java pushing any concepts onto you is bad. That means Java is programming you, you are not programming Java. OO is not pixie dust.
 
Old 11-15-2005, 04:18 PM   #13
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
Quote:
mispelled
It's "misspelled"
 
Old 11-15-2005, 04:48 PM   #14
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 111Reputation: 111
Just quit all of you. Everybody knows "misspelled" is a commonly misspelled word. It isn't even visually jarring to see it either.
 
Old 11-15-2005, 06:39 PM   #15
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,490

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
Quote:
Managing your own memory will also be much more efficient then having Java handle it for you, cause as a programmer, you should know exactly how the data flows.
That's "more efficient than having ..."

Well, I disagree with your comment about memory handling.

It is true than in an ideal world, a programmer should know exactly how the data flows, but in the real world, a C programmer has to deal with many libraries and foreign functions he just can't master enough to know if a returned value has to be freed or not.

This is leading to many subtle bugs, like pointer freed twice, or never (memory leaks), not to mention the other pointers errors.

There are certainly tools that ease the memory issues detection, but using them, and the whole task of building a memory bug free program is simply non productive. That time would be better used focusing on the real purpose of the program.

Garbage collection algorithms used in modern JVMs are faster and less intrusive than the old ones.

Moreover, there is no demonstration that malloc/free is faster and more efficient than using a garbage collector. When you call malloc, the library has to follow links until it finds a free location large enough to hold the size requested, when java needs memory, it just knows where free memory is and give it to the program, so this part should be faster in Java. When you free a pointer in C, there is a couple of links that are updated, while in Java, as you never free anything, no time is lost ...
Finally, in Java, the garbage collecting threads are free to move the memory blocks during their job, and this has the side effect of reducing the memory fragmentation. In C, no such thing is possible, due to the direct access required by the pointers, so you may need a much larger heap than in Java for the same memory usage profile, especially with programs running for several days.
Also, the garbage collector is running with a low priority, so the CPU cycles it uses are more likely to have a smaller impact on the program main task, while with C, all the memory handling is done when the program is running, so are always slowing it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Portable Cygwin oneandoneis2 Linux - General 1 04-01-2005 09:28 PM
portable home Tuttle Linux - General 2 03-22-2005 02:15 PM
Install on portable hd? Possible or not? greenpenguin246 Linux - General 1 03-11-2004 10:42 PM
Portable distros? Iriel Linux - General 1 12-13-2003 03:12 PM
Portable terminal mathi Linux - General 2 11-28-2000 08:52 AM


All times are GMT -5. The time now is 08:11 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration