The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > General Programming > C / C++


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Tags:

Closed Thread
 
LinkBack Thread Tools    Display Modes   
  #11 (permalink)  
Old 07-09-2007, 02:09 PM
rpgfan3233 rpgfan3233 is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jul 2007
Posts: 118
iTrader: (0)
rpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura about
Regarding the question on C being on the same level as C++, C++ is typically thought of as a higher-level language while C is a lower-level language. I personally have found C to be faster than C++ in some cases. However, as Bjarne Stroustrup explains, if C++ is any slower or any larger than C, it is due to the library implementors, who in my case would often mean Microsoft when I write applications in Windows XP. I often link against STLport rather than the normal stuff that comes with the MinGW version of gcc (which I used to then build gcc-4.1.2 on Windows, which I then used to build STLport, which I currently use now... that was a lot of whiches!)

Let me put it this way:
tst.exe - 557568 bytes
tst_stlport.exe - 374272 bytes


__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #12 (permalink)  
Old 07-09-2007, 07:33 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Quote:
I personally have found C to be faster than C++ in some cases.
are you talking about run-time or compile-time?

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #13 (permalink)  
Old 07-09-2007, 08:57 PM
rpgfan3233 rpgfan3233 is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jul 2007
Posts: 118
iTrader: (0)
rpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura about
Quote:
Originally Posted by HelloWorld View Post
are you talking about run-time or compile-time?
Hehe... I guess I should have mentioned that, huh? I'm talking about run-time. There's a nice long discussion here that basically explains how well-written C++ code should not be any slower than *equivalent* C code. If you have a template function in C++, the code generated shouldn't be any slower than the equivalent C code. In fact, C++ code CAN be faster than the equivalent C code. Like I've mentioned before (maybe in another thread), C++ isn't supposed to add any overhead, but that depends upon the C++ libraries that are used as well as one's own code. If you are 100% sure that your C++ code is as fast as you can get it and you still notice some lag, it is probably the libraries. In that case, look for alternatives. STLport isn't too bad, though you have to build it yourself. Then there are the BOOST libraries that seem to be so widely celebrated, though I haven't worked with BOOST libraries personally.

The bottom line: C++ can be good, if you use it right. C is naturally fast, but the features of C++ often allow for more rapid application development since you don't need to worry about recreating the same exact functions but with different names and arguments to reflect the data types used. C++ provides the ability to use generic programming to your advantage. That way, you don't have things like fgetc, getc and getchar, the first two to read a character from a file and one to read a character from stdout. In C++, you can have default arguments:
int getc (FILE * stream = stdin);

That way, if you only use getc(), you will read a file from standard input exactly like getchar() does. Also, fgetc wouldn't be needed because getc and fgetc already are basically the same thing, except that getc may be a macro (very useful, but dangerous at times). Congratulations. Three functions were slimmed down to one function.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
The Following User Says Thank You to rpgfan3233 For This Useful Post:
HelloWorld (07-10-2007)
  #14 (permalink)  
Old 07-10-2007, 08:17 AM
ccoonen ccoonen is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jun 2007
Location: Wisconsin
Posts: 317
iTrader: (0)
ccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished road
C++ is an object-oriented language whereas C is not, I definitely would go with C++ if you ever want to advance/move into other languages that use OOP.
The Following User Says Thank You to ccoonen For This Useful Post:
HelloWorld (07-10-2007)
  #15 (permalink)  
Old 07-10-2007, 08:34 AM
siLenTz's Avatar
siLenTz siLenTz is offline
Jr. Programmer
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jun 2007
Posts: 87
iTrader: (0)
siLenTz will become famous soon enoughsiLenTz will become famous soon enough
Easy explaination is: If you know C++, you know C 70% automaticly, But
if you know C, you automaticly know C++ only 30%

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #16 (permalink)  
Old 07-11-2007, 05:00 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Quote:
Originally Posted by siLenTz View Post
Easy explaination is: If you know C++, you know C 70% automaticly, But
if you know C, you automaticly know C++ only 30%
Isn't both of them shares the same libraries? Why is it only 30% if you learn C

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #17 (permalink)  
Old 07-11-2007, 06:24 PM
rpgfan3233 rpgfan3233 is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jul 2007
Posts: 118
iTrader: (0)
rpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura about
Quote:
Originally Posted by HelloWorld View Post
Isn't both of them shares the same libraries? Why is it only 30% if you learn C
Here are the C++ headers:
ios
iostream
istream
ostream
streambuf
sstream
fstream
string
algorithm
vector
bitset
queue
stack
deque
list
set
map

Here are the C++ headers for the C equivalents:
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h - not to be confused with string as above)
ctime (time.h)

Functions from C that I use in C++:
  • printf function family (cstdio) for when I need to convert data types more quickly than I can by using stringstreams (sstream), or for outputting data when I only need to use cout maybe once (the iostreams library is big)
  • system function (cstdlib) for executing a command line
  • time functions (ctime) for when I need to time something or simply output the time or for seeding a random number generator
  • char/string-to-integer/float functions (cstdlib) because they are convenient
  • rand and srand functions (cstdlib) for random numbers
Of course, that's only a handful of functions. However, for hobby programming I find that the others don't come up very often, especially since I haven't worked on a serious project. However, I've found them to be nearly invaluable. If you learn C++, you'll run across those. If you learn C, you'll probably still run across them, but you won't gain the C++ knowledge. I guess when you learn C++, you learn C simultaneously at times.

Certain things were discovered on a need-to-know basis like using sprintf to convert data types for an integer-to-string function when I noticed a horrible lag while using stringstreams from <sstream>. As for printf itself, I took some time away from C++ to learn some real C programming. I can't say that I liked certain things, but because I knew C++ somewhat well C wasn't too difficult to grasp, especially since the syntax is the same between the two. The worst part was trying to manage strings in C (character arrays), especially dynamic strings where you don't know the length of the string/array until later in your program. Once you work with the C++ string class, you'll find treating strings as character arrays to be somewhat difficult and pointless. The string class is very convenient.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
The Following 2 Users Say Thank You to rpgfan3233 For This Useful Post:
admin (07-11-2007), HelloWorld (07-11-2007)
Closed Thread


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 05:36 AM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50