Home » Community » Forums » General Programming » C is unnecessary
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic

Page:    «« 1 2 3 4 5 6 7 8 »»

 Last Thread Next Thread 
 C is unnecessary
Post New Topic  Post Reply 
quote:

double d;
char buffer[10];
sprintf(buffer,"%f",d); //whoops, what happens if d is too long



A better C programmer will use snprintf().

 User Rating: 1094   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Okay, and what if he didn't allocate a large enough buffer? Reallocate? Miss out on part of your input? Whatever the solution, it is empirically less optimal than the c++ solution.

Even snprintf is still too low level. Now you have to worry about buffer size - and it still suffers from the same lack of type information that sprintf has.

 User Rating: 1045   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Of course (responding to the title "C is unnecessary") one could argue that c++ isn't any more necessary.

 User Rating: 1002   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:
Original post by Ready4Dis
c++ where we'd have to inherit a base object, and use virtual functions, which are WAY slow)

You officially disqualified yourself from this discussion right there.



"To assert that the earth revolves around the sun is as erroneous as to claim that Jesus was not born of a virgin."
-- Cardinal Bellarmine


 User Rating: 1579   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link



"To assert that the earth revolves around the sun is as erroneous as to claim that Jesus was not born of a virgin."
-- Cardinal Bellarmine


OT:
in defense of the Cardinal, it was the Middle Ages. There was alot of misconceptions in those days. So the quote is a little unsupporting to "your" point.

And yes, I'm Catholic. but i can admit that the Church has f*cked up more times than it can count

Back on topic:
if you C++ can do "everything" that C can do, why use C (ignore the legacy code factor while answering this question)?



 User Rating: 1750   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

quote:
Original post by Enselic
[quote]Original post by kordova
But in some cases you simply _cannot_ do that.


Could you give me a concrete example?


int f();
 


The above has a different meaning in C than in C++. A simple search and replace won't be sufficient. In C it is implicitly a variable arity function, while in C++ it is a zero-argument function.

struct A {
   int foo;
};

struct A a;
int a;
 


The above used to be legal C code. I think it was changed in C99 (gcc is griping at me about it). This obviously isn't legal code in C++. Again, a search and replace won't be sufficient.

 User Rating: 1015    Report this Post to a Moderator | Link



Enselic, just a reminder, IF you use WinAPI/OpenGL, you should not say that we can dump C and use C++ all the way.

 User Rating: 1348   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:

The above has a different meaning in C than in C++. A simple search and replace won't be sufficient. In C it is implicitly a variable arity function, while in C++ it is a zero-argument function.



Actually, let me retract that statement. A regex based substitution should be sufficient to properly match and translate said forms. Although this would have to occur after the preprocessor has ran. Otherwise the matcher could attempt to translate:

#define (void) FOO

FOO f();
 


Which is a return-type cast, not a function declaration. Also working in function-pointers wouldn't be that bad.

 User Rating: 1015    Report this Post to a Moderator | Link

quote:
Original post by alnite
Enselic, just a reminder, IF you use WinAPI/OpenGL, you should not say that we can dump C and use C++ all the way.


I do all my OpenGL coding in c++. And what little Win32 coding is also done in c++.


 User Rating: 1045   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I am just saying that Win32 and OpenGL API use C, not C++. There is no such thing called OOP in Win32 and OpenGL API, they are all pure function calls.


Current project: A puzzle game.
% completed: ~10%
Status: Active.


 User Rating: 1348   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:

I am just saying that Win32 and OpenGL API use C, not C++. There is no such thing called OOP in Win32 and OpenGL API, they are all pure function calls.



Well there are such things as kernel objects... but I'll shutup about that.

 User Rating: 1015    Report this Post to a Moderator | Link

Ensylic,

Great question!

Keep it up my friend!

Strict C is probably faster than c++, but as long as you code smartly in c++, and take from C what is needed from C (example TYPEDEF), C++ will be almost, if not just as fast as C.

 User Rating: 934   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

when the C millisecond timer over flows in the 2030s or whenever its supposed to happen, then they'll be a reason to code in C, and I'll be makin' mega bux doin' it, so there.

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:
Original post by Bennettovia
when the C millisecond timer over flows in the 2030s or whenever its supposed to happen, then they'll be a reason to code in C, and I'll be makin' mega bux doin' it, so there.


Thats the funniest think I'v heard in awhile, please provide a link. It will be the Y2K+~30 bug, (of coarse the news will have to think of a better name).


Anyways, this is the way I see it, and it would be painfull if anyone posted after this without considering this:

If all the C compilers in the world could be replaced by C++ compilers, (ALL OF THEM, even the ones running on some old linux machine that hasn't been used for years and may never be again), then why not do it?

In its true form, isn't C++ completely backwards compatable with C? I was under the impression that it was, and I have not seen any evidence suggesting otherwise. Now I'm not saying that C++ compilers ARE C backwards compatable, I'm saying that those compilers would be made to be under the assumption that all C compilers would be made into C++ compilers. (obviously a few things could not be fixed, like if some c code used "class" as an identifier or whatnot, but shut up and don't argue about that, assume it would be fixed as well some how in a perfect way).

So, why not change them all? No extra person would have to learn C++, they could keep using C, or whatnot. C++ and C arn't DIFFERENT languages, C++ is just an extended version of C.

No one would be forcing anyone to use the extra feautures of C++ in this C removed world, so why not do it?

 User Rating: 1437   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:
Original post by alnite
I am just saying that Win32 and OpenGL API use C, not C++. There is no such thing called OOP in Win32 and OpenGL API, they are all pure function calls.



Programming in c++ doesn't require you to use OOP. Purely procedural programming is acceptable in c++, when it is appropriate. Class heirarchies are good when you need dynamic dispatch on one object, code sharing between similar objects is natural, or you need to specify an interface for functionality that the user can implement. Innappropriate use of OOP is just as bad as the lack of OOP when it would be useful.

 User Rating: 1045   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:
Original post by RhoneRanger
Strict C is probably faster than c++, but as long as you code smartly in c++, and take from C what is needed from C (example TYPEDEF), C++ will be almost, if not just as fast as C.


People don't seem to understand one important point regarding performance.

c++ is not slow. If you use a feature of c++ that has some overhead, you're going to pay for it. If you were using C and you needed that feature, it's not going to magically be faster because you are using C. It's going to be just as slow, if not slower, and a whole heck of a lot harder to understand, since the language is lacking the idioms needed to express what is going on. Furthermore, this C emulation of c++ features is going to be harder to developer, harder to maintain, and more prone to errors and bugs than the c++ equivalent.

 User Rating: 1045   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:
Original post by Senses777
[quote]Original post by Bennettovia
when the C millisecond timer over flows in the 2030s or whenever its supposed to happen, then they'll be a reason to code in C, and I'll be makin' mega bux doin' it, so there.


Thats the funniest think I'v heard in awhile, please provide a link. It will be the Y2K+~30 bug, (of coarse the news will have to think of a better name).


Anyways, this is the way I see it, and it would be painfull if anyone posted after this without considering this:

If all the C compilers in the world could be replaced by C++ compilers, (ALL OF THEM, even the ones running on some old linux machine that hasn't been used for years and may never be again), then why not do it?

In its true form, isn't C++ completely backwards compatable with C? I was under the impression that it was, and I have not seen any evidence suggesting otherwise. Now I'm not saying that C++ compilers ARE C backwards compatable, I'm saying that those compilers would be made to be under the assumption that all C compilers would be made into C++ compilers. (obviously a few things could not be fixed, like if some c code used "class" as an identifier or whatnot, but shut up and don't argue about that, assume it would be fixed as well some how in a perfect way).

So, why not change them all? No extra person would have to learn C++, they could keep using C, or whatnot. C++ and C arn't DIFFERENT languages, C++ is just an extended version of C.

No one would be forcing anyone to use the extra feautures of C++ in this C removed world, so why not do it?


Take a look at this story.

I used to use blue ball pens for all of my wirting. Then one day I found that there is a pen which can be used the same way as my blue ball pen. In addition, it gives me black colour too. If all blue ball pens could be replaced by this new pen, should the blue ball pen be abondoned and give the reason that there is nothing you can write using the blue pen that you cannot write using the new pen. Moreover, no one would force you to use the black colour even all the blue pens were replaced by the new pen.
What do you think?

My opinion is that if all I want is a blue pen because I do not need black colour for anthing of my writing, I do not have any reason to replace my blue pen with the new one even it gives something extra. It goes without saying that the new pen will be heavier because it contains more than the blue pen, namely the black pen.

As for C and C++, it is similar. C++ provides something extra and does not force you to use it. However, it is very likely that a C++ compiler is larger than a C compiler and C++ compilers takes longer time to compile.

So my conclusion is that C has its own use as someone has already pointed out. Therefore C is still necessary for someone who want to have smaller and faster compiler.

 User Rating: 1017   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

before 2030 the time_t structure will be extended with additional bits and won't overflow.

also C is in fact a newer language then C++, the C standard was revised in 1999 and C++ in 1998, the new things in C99 gives C features that isn't available in C++.

Also it's a lot easier to support a C implementation, so low spec systems will always have a C compiler, but not always a C++ compiler, as well as the CRT vs the C++ runtime library.

For example my OS uses C because it's easier to make sure exactly how it works, because there is no vtables or rtti fields added to my structs, unless I add them myself.

--------------------------------

"I'm a half time coder, full time Britney Spears addict"
Targhan

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

*Enselic wakes up from a nice swedish sleep, perform some social activities and then read all the posts*

quote:
darkchrono4
Maybe C++ is better, but I'm just a hobbyist so I don't really care. I taught myself how to use C and never looked back. I've diddled with C++ and know how to do classes, overloading, etc. I just don't really like it. To me procedural is the way to go. Functions make more sense to me. Usually if I kind some code snippet that I want to use and its in C++ I convert it to C.


If you stick to C you will never even have the oppurtunity to use templates, classes and so on. If you move to C++ you have nothing to loose!

quote:
kordova
Of course (responding to the title "C is unnecessary") one could argue that c++ isn't any more necessary.


C is not necessary since we have C++!

quote:

struct A { int foo;};
struct A a;
int a;

The above used to be legal C code. I think it was changed in C99 (gcc is griping at me about it). This obviously isn't legal code in C++. Again, a search and replace won't be sufficient.


Allow me to lol. Why the heck would you want to use the same name for an int as a struct? Bad programming if you ask me.

quote:
Original post by alnite


Enselic, just a reminder, IF you use WinAPI/OpenGL, you should not say that we can dump C and use C++ all the way.

You can use C++ for those libaries too! Now could you leave? Yes you annoy me...

quote:
sjelkjd
Programming in c++ doesn't require you to use OOP. Purely procedural programming is acceptable in c++, when it is appropriate.


THAT is why C is not necessary and that is why I started this thread.


____________________ ____ ___ __ _
Enselic's Corner - My site. Go test my game Spatra and see if you can beat it onto the Official Spatra Top 10.
CodeSampler.com - Great site with source for specific tasks in DirectX and OpenGL.

[edited by - Enselic on May 4, 2003 9:27:46 AM]

 User Rating: 1486   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

quote:
Original post by sjelkjd
Programming in c++ doesn't require you to use OOP. Purely procedural programming is acceptable in c++, when it is appropriate.
So...what makes a code C++? and what makes a code C? How do we differentiate them?
EDIT: other than function overloading. Win32 API uses extern "C"


Current project: A puzzle game.
% completed: ~10%
Status: Active.


[edited by - alnite on May 4, 2003 10:09:31 AM]

 User Rating: 1348   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:
Original post by sjelkjd
As for some of the claims that C is a language for bugs and for buffer overuns, I would suspect that most people started with C, learned from their mistakes at the same time that they took on C++. There's nothing different in C then C++ when writing debug code that does bounds checking with memory fences and the like. You can write equally buggy ode in C++.



Not exactly. Most buffer overuns are of the form:

//C
char buffer[100];
scanf("%s",buffer); //whoops, use can enter more than 100 chars and trash the stack

//c++
std::string buffer;
cin>>buffer; //can be as long as you want

Here's another classic:

double d;
char buffer[10];
sprintf(buffer,"%f",d); //whoops, what happens if d is too long

//c++
double d;
ostringstream out;
out << d; //dynamically allocates

I can really go on and on. Like I said before, you certainly can program poorly in c++ (all the C code I showed is valid c++) - but it is poor style. Proper c++ uses the standard library's mechanisms:
strings for string manipulation
vectors for dynamic arrays
stringstreams for formatting
streams for type-safe IO
etc...




I highly doubt IE uses scanf, nore any other common program with a buffer over-run/flow error that could be used to gain access to your machine, or do something bad to it. All of that stuff is normally when working with winsocks, and reading in packets, etc.


quote:

Sounds like you don't know what you are talking about. My point is that c++ provides mechanisms in the language that you have to hack around as a C developer. All the planning in the world isn't going to make an C implementation of virtual functions pretty.

Using c++ doesn't mean having large class heirarchies, or making everything a virtual function. You have that option, and in many cases polymorphism is exactly what you want. In other cases, it falls woefully short(as anyone who has used generic functions in Lisp knows). You don't have to sacrifice performance for productivity in c++ - you simply have more language idioms available to express your problem.



I am using a C++ compiler, but I removed all parts of C++ from the raytracer core. I received a hefty 400% speed boost from doing so. That was using the EXACT same intersection code, so if that was the part taking the longest, and I got a 400% boost in speed... (yes, both were testing in release mode) that must really say something.

My point was, if you have a problem with variable names in functions, you obviously have A.) bad variable naming techniques, and/or B.) to large of functions that you can't easily see what's happening. Bad planning will mean hard to read code. Using C code, it is easy enough to organize your code in a readable manner, place common functions into a seperate files, and give it a name that describes the commoness. I also wanted to state, that I DO use C++, and to a pretty large extent (more often than I use straight C), so I do know how usefull C++ is and can be, but in most cases, straight C code is faster than using the "advanced" features of C++. Same goes/went for my older 3d software engines... sure C++ was alright, but C was faster... and I wrote inline assembly for certain aspects because that was even faster than C. I haven't done much in the way of assembly & C/C++ in msvc (that was in the days of turbo c/c++), but I may re-write sections of my raytracer in assembly... try converting C -> assembly.. not that difficult... now trying converting C++ -> assembly.. omfg, we have to re-write it and re-plan it completely.


--- Edit ---
Stupid double qouteing doesn't work .

[edited by - Ready4Dis on May 4, 2003 9:59:49 AM]

 User Rating: 1053   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:
Original post by Enselic
You can use C++ for those libaries too! Now could you leave? Yes you annoy me...
I didn't claim you couldn't. Those libraries are written in C (at least the header files where functions structs etc are defined). If you use them, you use C.

 User Rating: 1348   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:
Original post by Enselic
THAT is why C is not necessary and that is why I started this thread.


Why/Who are you trying to prove this to? I'm sure several major games have been written in C so maybe you should speak with the Quake guys as I'm sure they would be fascinated by your _opinion_.

 User Rating: 1002   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:
Original post by kordova
Why/Who are you trying to prove this to? I'm sure several major games have been written in C so maybe you should speak with the Quake guys as I'm sure they would be fascinated by your _opinion_.


He just wanted to get a megarant going. At least it's still on topic.

Nobody's saying that C isn't useful, but C++ was made from the get-go to be "a better C." Anything you can do, I can do better, and all that. What's the harm in using C++ that way?

Is there any downside to using C++ instead of C? The only ones I can think of are the availability of C++ compilers on weird platforms, and that C++ doesn't compile as fast.


I'm hip because I say "M$" instead of "MS".

 User Rating: 1093   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:
Original post by kordova
Why/Who are you trying to prove this to? I'm sure several major games have been written in C so maybe you should speak with the Quake guys as I'm sure they would be fascinated by your _opinion_.

Quake uses C++ virtual functions, which are
quote:
WAY slow

(sarcasm) but they're implemented in C. This argument is moot as I think Doom 3 is being written in C++.

 User Rating: 1317   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link
Page:    «« 1 2 3 4 5 6 7 8 »»
All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: