Click to See Complete Forum and Search --> : C or C++?


Arjay
02-15-2004, 08:16 PM
Probably been asked a thousand times, unfortunatly this forum doesn't stretch back to far, and also the word 'C' is less than the three charcters needed to use the search tool.

Anyway my questions is a simple one. For the last 1.5 years i have been studying Java and later on this year i wouldn't mind trying another language, mostly so i am not restricted to one only. Because i use Linux i was thinking that C or C++ would be better, would it matter which? If i learn C++ could i do all the things that could be done in C and vice versa (well eventually). Am i right in saying that C is more of a mid-level language, whereas C++ a high-level, or can both be either?

Just thought i would ask because i am undecided on which to go for.

Thanks for any opinions :-)

bwkaz
02-15-2004, 08:41 PM
Originally posted by Arjay
unfortunatly this forum doesn't stretch back to far, Sure it does, if you change the dropdown at the bottom of the thread list so that it reads something like:

Showing threads 1 to 25 of 156, sorted by "last post time", in "descending" order, from "the beginning".

You have to change the last one from "45 days" to "the beginning", but you'll be able to see all the threads.

Anyway, as to your question, you could just learn them both... ;)

But if you really want to choose, probably C. C is small enough to fit in your head at once, unlike C++. (That's mostly because C++ has to be backward-compatible with C.) Half the time with C++ (at least in my experience) it takes a lot of thought to figure out if something is valid or not. With C, it's relatively obvious.

But then, I won't argue that std::string is a heck of a lot safer (and easier) than char pointers, so ... hmm. Not a real great answer, is this? ;)

Trogdor
02-15-2004, 08:45 PM
Hard to give you advice without starting a holy war, so I'll stick to the facts, and try to avoid opinions. Most of the Linux kernel, and most GTK applications are written in C, which is mid-level. QT applications are generally C++. C++ is not a true superset of C, but Objective-C is. C++ (and Obj-C) are Object-Oriented, which makes big projects much much easier to make and maintain. C applications are smaller and run faster. I'd recommend learing C++, but it doesn't make a big difference because knowing one is 90% of knowing another, and knowing Java is a big step.

Just my 200 000 000 000 Yen ($0.02).

Hussain
02-15-2004, 09:17 PM
Since you work with java ( high object oriented ) you know most if not everythign in C :)

java is based on C !!
so if you feel woried you can pick a books about C and hack it in less than two weeks :) lool

Java has somethign to do with future ..so i recommend to program in Java >

PolteRGeisT
02-15-2004, 10:29 PM
C is meant for speed. Most software written for non-UI programs are written in C, at least from my experience. You won't see a (good) OS written in anything other than C. You can still write large, sophisticated programs in C, but it becomes more complicated, despite running better. (The Quake engine comes to mind, that thing is still being used today!)

C++/Java are for much larger and more complicated projects (with the exception of OS's, go figure :rolleyes: ). You can do a lot of neat things with C++ that can make large projects easy to maintain. The cost is performance, however, the reduction in production time tends to make up for this. Writing simple programs in C++ is unneccesary, most of the time.


That's my $0.02. don't flame me plz :)

Citadel
02-16-2004, 10:32 AM
I wouldn't bother learning C++ however std::c++ is a good language, but it's not easy to learn because there is no one single website to go to and find all of the resources. Std::c++ has built in features that support multi-paradigm programming. It is the most misunderstood and misused in history.

Learning ANSI C is recommended because most of the systems including the kernel are written in C. When Unix first came out the C language and the Unix platform were integrated, they were basically one and the same. It's like C# in the sense that it will be sold as part of Longhorn.

Learn ANSI C if you want to learn how your system works and than have control over it. If you have control over your system than theoritically you can change it and make it different, in fact you could have a system which is unrecognizable to the world and 100 percent secure. Unlike Java, the C language will open up your desire to know about implementations (source code) and protocols (X11, HTTP, RFC's, etc). With C you have power and control over the factors of production, it's anti-vendor. Widget toolkits (GTK+, QT) are okay, but the real power is in the most general low level libraries, the skeleton that lies underneath everything, yet since Linux is open source you can discover from the ground up how it all works. The C langauge is irrelavant, it's the systems that are important.

madcompnerd
02-16-2004, 10:56 AM
UI -> C++
Any single developer project -> C

Otherwise, it just depends on if you need to use classes (data/function encapsulation) or not.

Let me tell you though. If you do it in C++ you'd better state the purpose of classes. Going through undocumented classes is hell. The Com S department here seems to think that's a good part of training us.

Citadel
02-16-2004, 11:26 AM
Go to kernel.org and download library source code, for example:

1) glibc.2.1.2.tar.gz
2) glibc-linuxthreads-2.1.2.tar.gz
3) linux-2.6.2.tar.gz

This is the reason why you learn C instead of Java/Mono/Perl/Python. This code would be worth several billion dollars but because of the GPL it is free. If all you want to do though is build some fancy looking windows than stay with Java.

Burn this code to CD as data files and keep it safe. There could be a day when it is not available anymore.

Citadel
02-16-2004, 01:40 PM
If you want to look at the actual source code for the C libraries in case you choose to learn C, than the code is in Glibc, for example:

[prompt]$ ls ~/stdio
clearerr.c fileno.c fsetpos.c linewrap.c rewind.c vscanf.c
fcloseall.c fmemopen.c ftell.c linewrap.h setbuf.c vsnprintf.c
fclose.c fopen.c fwrite.c Makefile setbuffer.c vsprintf.c
feof.c fopncook.c getc.c memstream.c setlinebuf.c vsscanf.c
ferror.c fputc.c getchar.c newstream.c setvbuf.c
fflush.c fputs.c getdelim.c obstream.c stdio.h
fgetc.c fread.c gets.c putc.c ungetc.c
fgetpos.c freopen.c glue.c putchar.c vasprintf.c
fgets.c fseek.c internals.c puts.c Versions

Arjay
02-16-2004, 09:53 PM
Cheers folks,

You've left me some good points to think about, so that's what i'll go and do. Out of the two of them i keep thinking C.

Thanks again for your input :-)

Strogian
02-16-2004, 11:39 PM
Originally posted by Arjay
Cheers folks,

You've left me some good points to think about, so that's what i'll go and do. Out of the two of them i keep thinking C.


excellent. ;)

bwkaz
02-16-2004, 11:45 PM
Originally posted by Citadel
I wouldn't bother learning C++ however std::c++ is a good language, Uhh... where did you get std::c++ from? Did you make it up? If so, what do you mean by it? I assume the std:: namespace in libstdc++ -- if so, then of course you realize that using the functionality of the std:: namespace requires that you know the C++ language. Right?

When Unix first came out the C language and the Unix platform were integrated Too bad Unix is older than C, then, isn't it...

http://www.catb.org/~esr/jargon/html/U/Unix.html

http://www.catb.org/~esr/jargon/html/C/C.html

Notice especially how Unix was written in 1969, then ported to C (which was created "in the early 70s") in 1972. In fact, reimplementation of Unix was one of the first things C was used for -- it's not the case that one of the first things done with Unix was reimplementing it in C.

in fact you could have a system which is unrecognizable to the world and 100 percent secure. No system on earth is 100% secure. The only way you can get a system to be 100% secure is to unplug it from everything (including the power), lock it in a vault, and then destroy the vault's only key. Otherwise, somebody somewhere will have enough time to break into it (assuming they have a reason to).

Unlike Java, the C language will open up your desire to know about implementations How do you figure that one? The fact that many of my programs and libraries are written in C is not what motivates me to look at their implementation -- most often, it's problems in some other program that uses the library, or problems in the program itself (or my environment) that motivate me to look at the source. Language has little or nothing to do with it.

Go to kernel.org and download library source code, for example:

1) glibc.2.1.2.tar.gz
2) glibc-linuxthreads-2.1.2.tar.gz
3) linux-2.6.2.tar.gz You can't even get glibc from kernel.org, and glibc 2.1 is ancient anyway.

You'd be much better off going to ftp://ftp.gnu.org/gnu/glibc/ and getting glibc 2.3.X (though 2.3.2 has some security holes, and Ulrich Drepper, the main maintainer, apparently doesn't want to distribute tarballs anymore, so you might have to track glibc CVS if you want current, secure, working code... then, there's the fact that linuxthreads is not POSIX compliant in many areas, which is why NPTL was created, and NPTL is only part of glibc CVS for now also).

This code would be worth several billion dollars How do you figure?

Burn this code to CD as data files and keep it safe. There could be a day when it is not available anymore. Ehh? No, not really. That code was released under the GPL. Any version released under the GPL will always be under the GPL -- it can never be (legally) made proprietary. That's the point of the GPL. The FSF can't even change it anymore -- they can't renege on their license. They can cause certain copies of it to be licensed differently, but they won't.

I'm not sure how you see it becoming unavailable, in other words.

And you can program in C just fine without looking at the glibc source. That's why the man-pages package exists, and that's why glibc installs manpages with itself. The man-pages package documents most system calls (for example, socketpair(2), open(2), pipe(2), ioctl(2), etc.). The glibc package installs man pages for most of its functions -- most everything in section 3. Stuff like printf(3), pthread_create(3), atan(3), and aio_write(3).

sploo22
02-17-2004, 09:04 AM
Originally posted by bwkaz
I'm not sure how you see it becoming unavailable, in other words.


Uhhhh... it looks to me like sheer paranoia, maybe? :rolleyes:

Citadel
02-17-2004, 12:37 PM
Originally posted by bwkaz Uhh... where did you get std::c++ from? Did you make it up? If so, what do you mean by it? I assume the std:: namespace in libstdc++ -- if so, then of course you realize that using the functionality of the std:: namespace requires that you know the C++ language. Right?

Too bad Unix is older than C, then, isn't it...

http://www.catb.org/~esr/jargon/html/U/Unix.html

http://www.catb.org/~esr/jargon/html/C/C.html

Notice especially how Unix was written in 1969, then ported to C (which was created "in the early 70s") in 1972. In fact, reimplementation of Unix was one of the first things C was used for -- it's not the case that one of the first things done with Unix was reimplementing it in C.
C and Unix are tied together. In order to get rid of C you would have to write a new operating system. Yes I mean C++ and the Standard Library, in implementation is libstdc++.
No system on earth is 100% secure. The only way you can get a system to be 100% secure is to unplug it from everything (including the power), lock it in a vault, and then destroy the vault's only key. Otherwise, somebody somewhere will have enough time to break into it (assuming they have a reason to).
A system with an unrecognizable interface and some unrecognizable systems programs is secure.
How do you figure that one? The fact that many of my programs and libraries are written in C is not what motivates me to look at their implementation -- most often, it's problems in some other program that uses the library, or problems in the program itself (or my environment) that motivate me to look at the source. Language has little or nothing to do with it.
I don't want to depend on anybody. I need to have control over the systems software.
You can't even get glibc from kernel.org, and glibc 2.1 is ancient anyway.

You'd be much better off going to ftp://ftp.gnu.org/gnu/glibc/ and getting glibc 2.3.X (though 2.3.2 has some security holes, and Ulrich Drepper, the main maintainer, apparently doesn't want to distribute tarballs anymore, so you might have to track glibc CVS if you want current, secure, working code... then, there's the fact that linuxthreads is not POSIX compliant in many areas, which is why NPTL was created, and NPTL is only part of glibc CVS for now also).
Get it where ever you can. It is irrelavent.
How do you figure?

Ehh? No, not really. That code was released under the GPL. Any version released under the GPL will always be under the GPL -- it can never be (legally) made proprietary. That's the point of the GPL. The FSF can't even change it anymore -- they can't renege on their license. They can cause certain copies of it to be licensed differently, but they won't.

I'm not sure how you see it becoming unavailable, in other words.
It can become unavailable if a controlling interest gets it's hands on Linux. I don't trust the industry because it supports a monopoly, which does not give away any control over the technology. Power elites that want Linux to disappear. I am a millionaire, so I'm probably just as corrupt as any, I play the same game as them.
And you can program in C just fine without looking at the glibc source. That's why the man-pages package exists, and that's why glibc installs manpages with itself. The man-pages package documents most system calls (for example, socketpair(2), open(2), pipe(2), ioctl(2), etc.). The glibc package installs man pages for most of its functions -- most everything in section 3. Stuff like printf(3), pthread_create(3), atan(3), and aio_write(3).
People have different goals. If I only had a skeleton of the most general systems, than I would be interested in writing specialized applications. I want control over my system before I write any software. Writing software is a leasure activity, it is a pleasure.

Citadel
02-17-2004, 01:24 PM
In order to just write solutions. To write programs and get paid for them, I think that the best languages are Perl/Python and the use of MySQL and Apache. It might and might not be worth using Mono. Knowing some Java is not a bad idea, but Java is proprietary and supporting it means that you support some dictator.

It's possible to do stuff in C, because there's GTK+. I don't think that the C language will sell very well though, and solution development is mostly about sales hype. Mono will do better and a Mono/Perl/Python combination would sell a lot of tickets. And that's the point of that type of programming, to sell tickets to the fans. Maybe quality software solutions are a liability. They interfere with sales because the client has too much control. With Mono/Perl/Python people will be getting better quality and they will have more control because things won't change as fast as they do with proprietary software. The vendors rely on a changing environment, not an evolving one. The OP wanted to look beyond Java. That's a good idea, because Sun has too much control. The C language or std::c++ isn't the best choice unless you want to develop systems software, but to do so you have to first study systems which are mostly implemented in C. I like studying systems and I can relate to it, my goal is to control the platform that I use. I find solution development with C to be odd, and I think that C is good but I like std::c++ better, however it is more difficult, in fact I'd like to see a tighter integration of C and std::c++, a new systems language. There are papers on Stroustrups website that talk about this. I like the idea, but ultimately I value the systems and protocols more than any language. I'm stuck with the C language. Maybe when or if there isn't a monopoly controlling the industry I'd start a business, but because of the presence of a monopoly it doesn't make much sense. I was thinking though, that I might start up a website that supported some of these open source technologies. I think that Oreilly and Sourceforge do a great job. I've supported Oreilly through massive book orders :+)

bwkaz
02-17-2004, 08:49 PM
Originally posted by Citadel
Yes I mean C++ and the Standard Library, in implementation is libstdc++. And uses the C++ language. Therefore, in order to use the library, you have to know the language. Which was my whole point -- you can't separate C++ from whatever it was that you meant by std::c++.

A system with an unrecognizable interface and some unrecognizable systems programs is secure. This hypothetical system suffers from the exact same problems as the one that's locked away. It can't actually do anything interesting, because to do anything interesting, you have to be able to interoperate with other machines.

It can become unavailable if a controlling interest gets it's hands on Linux. It sure looks to me like you don't get the GPL, or copyright law.

It's already been released under the GPL. It's already out in the open. There's nothing that anybody can do about that, black-helicopter-SCO-will-get-us conspiracy theories notwithstanding.

People have different goals. I want control over my system before I write any software. Writing software is a leasure activity, it is a pleasure. Same here -- I write stuff in my spare time.

And I don't use the library source code to do that -- using the library source code would be about ten thousand times harder when the documentation is right there already.

gamblor01
02-17-2004, 09:04 PM
Learn either one of them and honestly you'll have a nearly perfect grasp of the other. In fact, if you can program in Java, you shouldn't have any problem moving to either C or C++. They're nearly identical, though I must say I have to complain that C doesn't allow classes, while C++ does. Either allow structures, but classes are a little more powerful because structures don't have class methods. Structures also make everything public by default, but if you're programming properly and defining what's public and private already anyway, it really shouldn't matter.

I'd say pick one and learn it. I personally prefer C++ but learn whatever you want. They're not that much different anyway.

maccorin
02-17-2004, 09:11 PM
Originally posted by Citadel
snip...

Don't use java because it is proprietary? but use C#? wtf ? Please explain to me how C# is any less proprietary the java, sure mono is OSS, but isn't blackdown OSS as well?

bwkaz
02-17-2004, 10:34 PM
See, that's the thing. It seems like every other day that Citadel switches back and forth on whether .Net is good or bad, and/or on whether Java is good or bad. :D

I use C# at work, and while it's not the greatest, it does get a few things right. As a programmer, it's (most of the time) nice to work in at least. The issues I have with it are that it doesn't do enough inside the runtime -- I'm still scrambling to find native APIs to handle serial communication, for example. And network sockets are nice, but when calls to some functions block, and they aren't interruptible because the blocking isn't in managed code, it gets to be a pain to interrupt your server thread when your program is going down. Of course, that's ignoring the portability / open source factor -- that's the biggest problem I see, and one that I'm glad that Mono and DotGNU (two separate implementations of the same thing) are addressing.

Mono and DotGNU are completely open source -- Blackdown is just a repackaging of the Sun JDK or JRE, and is still subject to Sun's license. I think gcj (the gcc frontend for Java) is open-source, though, and I'm pretty sure it has a good chunk of the Java runtime done, too. But I'm not positive, and it's been a while since I looked for sure.

Trogdor
02-18-2004, 12:20 AM
Originally posted by Hussain
Since you work with java ( high object oriented ) you know most if not everythign in C :)

java is based on C !!
so if you feel woried you can pick a books about C and hack it in less than two weeks :) lool

Java has somethign to do with future ..so i recommend to program in Java > Uhhh . . . C is function-oriented. C++ is object oriented. You mean c++.

Citadel
02-18-2004, 10:37 AM
Originally posted by Trogdor
Uhhh . . . C is function-oriented. C++ is object oriented. You mean c++.

C++ is object oriented but std::c++ is multiparadigm.

On another note regarding Java, it's not a good idea because of it's closed nature. ESR called for Java to be open sourced recently because he wants to ensure Java's future. Vendors tend to change product lines every seven or eight years and discontinue and than make it impossible to use old languages and libraries. Under open source Java could never be taken away. It would be available for the next 300 years instead of the next 10.

Mono as far as I know is OSS but I'm not 100% sure it is. The only garuntee is when it is licensed under the GPL.

If I were to choose a programming model for solution implemenation than it would be Perl/Python.

bwkaz
02-18-2004, 08:06 PM
Originally posted by Citadel
C++ is object oriented but std::c++ is multiparadigm. Again: you cannot separate the contents of the std:: namespace from the language that allows programmers to use it! If the std:: namespace is multi-paradigm (which it is not, but that's not the point right now), then the C++ language would HAVE to be also, or you wouldn't be able to use the stuff in that namespace from the language.

And the std:: namespace is not multi-paradigm. Everything in it is an object (actually, most things in it are classes, like std::iostream, but each of the few "things" that it actually creates are instances of those classes, like std::cout and std::endl).

However, I can program procedurally in C++ just fine -- heck, it still supports goto, so I can program in whatever paradigm came before procedural programming, using goto's.

It's not quite possible to program functionally. Pointers to functions in C++ can't be acted upon like functions themselves could be in Common Lisp: for example, you can't create a function that takes another function as its first argument, hardcodes the first parameter, and uses the rest of its parameter list that it received as the rest of the parameter list of the other function. But it is close, in that you can pass pointers to functions around at least.

Obviously it can do OO.

And what else is there? Not that it matters -- it can do three (and a half) paradigms already, so it's therefore multiparadigm.

Citadel
02-18-2004, 09:07 PM
I can do whatever the hell I want. I'm rich!
:+p

Citadel
02-18-2004, 09:31 PM
...besides, I'm talking about Standard C++, not just the standard library. And I'm done talking about it.

maccorin
02-18-2004, 11:23 PM
1) why do you keep pointing out that your rich... no one cares

2) wtf is std::c++, I _assumed_ that you were attempting to talk about the std library, because that's whats in namespace std..., and were just trying to be creative, but if your NOT talking about the library, then you obviously have no knowledge of what your talking about...

sorry, im just ornry, and sick of people using buzzwords that they heard in some half-cocked article from a .NET magazine to sound smart... if you don't know something ask for help. If someone else asks a question only answer it if you are somewhat certain of the content

Citadel
02-18-2004, 11:35 PM
How do you know that nobody cares. I got at least one private message.

Oh yeah, I read a .Net article and now I know everything. Good one buddy. :+)

Maybe you should stop licking your dogs *** and you won't be sick anymore.

bandwidth_pig
02-19-2004, 09:04 PM
http://dictionary.reference.com/search?r=2&q=ornery

We all have our days. :D

Citadel
02-20-2004, 02:27 PM
I can't even get that damn Mono thing installed. The rpm's fail, and only a couple of the sources build, the rest fail. Ultimately it just ends up clogging up my system. lol.

When you consider that the libraries consist of over a million lines of code, it's really something. In a way though it's also scary, is all of that compexity necessary. You would think that an effort like that, that you would be able to use those libraries for the next 300 years. Sure they will evolve but radical change would be counter productive. In the case of radical change it would be better to ignore those monolithic illusions.

bwkaz
02-20-2004, 08:13 PM
The RPMs fail, that's a surprise. :rolleyes: What error did you get again? Missing dependencies? You did install them in the correct order, right?

The source was really easy to install, actually. Do mono first, then mcs if you want a mono-runtime-compiled C# compiler, rather than a gcc-compiled compiler (I had to "make clean" in mcs' build directory after a failed attempt to compile it before mono). Basically, mono builds a gcc-compiled mcs, and mcs builds an mcs-compiled mcs.

If your .Net programs will use System.Drawing, then you need to install Cairo, then libgdiplus, both before mono I think (though I didn't compile either of them myself, so if they complain that mcs isn't found, install them after mono).

If you need a locale other than the "neutral" one (or whatever the default one is), then you need to install ICU before mono (again, I think -- didn't do this one either, so it might go after mono).

Like I said, it's not that hard. Nothing that a simple reading of the release notes didn't highlight (http://go-mono.com/archive/mono-0.30.1.html).

Fryguy8
02-20-2004, 09:54 PM
Java being totally OOP, you'll have an easier time learning C++, and from there you can just unlearn a few things to get C, and just switch back and forth. But basically after a few syntax changes, pointers, and a different library set (which is a bigger deal than I'm making it out to be, but), you know c++ from java.

Citadel
02-24-2004, 05:02 AM
With either C or C++, on Linux you have it made, because you have the source code. You have the source for the libraries, the compiler, and the platform itself. Look into that code too, if you want to understand more about your system. The source code is the key to a stable long term investment and it distinguishes Linux as a vendor neutral platform. All of the answers are in the code itself.

crow2icedearth2
02-26-2004, 01:43 AM
anyone have some good e books to learn c. or some good resources that teach u from knowing nothing to be coming a good programmer in c. I have very basic knowedg of programming.... have had a few courses . i want to learn c then learn c++

thanks

bandwidth_pig
02-26-2004, 08:30 PM
Practical C Programming is a great book:

http://www.amazon.com/exec/obidos/tg/detail/-/1565923065/qid=1077841466//ref=pd_ka_1/002-9293527-8421601?v=glance&s=books&n=507846

C How to Program is quite good also:

http://www.amazon.com/exec/obidos/tg/detail/-/0131426443/qid=1077841496/sr=1-2/ref=sr_1_2/002-9293527-8421601?v=glance&s=books

I am not ready for this book yet, but have it and it looks quite good:

http://www.amazon.com/exec/obidos/ASIN/0131774298/qid=1077841542/sr=2-1/ref=sr_2_1/002-9293527-8421601

The Standard C Library is one I have been meaning to pick up. I think it will make a great reference.

http://www.amazon.com/exec/obidos/tg/detail/-/0131315099/qid=1076259481/sr=5-3/ref=cm_lm_asin/002-9293527-8421601?v=glance

The C Programming Language is pretty much the defacto standard book for starting out. But it's a bit dated. But very worth reading:

http://www.amazon.com/exec/obidos/ASIN/0131103628/ref=pd_sxp_elt_l1/002-9293527-8421601

I'm also reading C a reference manual, which is quite good.

http://www.amazon.com/exec/obidos/ASIN/013089592X/ref=pd_sxp_elt_l1/002-9293527-8421601

Read these and you'll gain a whole lot of ground.

crow2icedearth2
02-28-2004, 01:54 AM
what about open source books ....

online books , etc ???

Hussain
02-29-2004, 01:06 PM
A good statement to be quoted :
"Learning C is a first step in learning C++ " ..

okay .. the quesion is ,if someone has studied C .and wants to move to C++ , what he\she has to do ? reading a book a book about C++ from the start ??!! No ..so what the subjects he has to study and practice ??? I think this is a good quesion :)