![]() |
|
|
|
| ||||||
|
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: |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |||
| 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 ![]() |
| |||
| 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. ![]() |
| The Following User Says Thank You to rpgfan3233 For This Useful Post: | ||
HelloWorld (07-10-2007) | ||
| |||
| 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. __________________ Day Cares | Golf Courses | Disc Golf Courses | Campgrounds | Ice Rinks | Paintball Fields | Dentists | Plastic Surgeons | Aging Jokes Catholic Churches | Lutheran Churches | Methodist Churches | Episcopal Churches | Clean Jokes |
| The Following User Says Thank You to ccoonen For This Useful Post: | ||
HelloWorld (07-10-2007) | ||
| |||
| Quote:
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++:
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. |
| The Following 2 Users Say Thank You to rpgfan3233 For This Useful Post: | ||
admin (07-11-2007), HelloWorld (07-11-2007) | ||
![]() |
| Thread Tools | |
| Display Modes | |
| |