The C programming language. Is anyone really using it, or is it just really outdated?
And why would you use C instead of C++?
Are you using C. If so; why?
What really is the difference?
Make a post about it.
C can be used to write low-level code, like drivers or operating system kernels. It's also used a lot on embedded systems.
C can be often more optimized at compile time which can lead to faster solutions, but tbh there isn't really much reason to use C except for maintenance on old systems, writing lower-level code, and preference.
C++ can be used as low-level as C and I'm pretty sure it can also be optimized as good as C++, though with C you can hand-control things a little easier by not being tempted to use C++ solutions with overhead you really want to and can work around.
It's easier to write a C compiler than a C++ compiler, due to the smaller standard obviously. As such for quite unpopular platforms you might not be able to use C++ though C; but I think there are C++ to C translators.
Maybe you could also use many parts of g++ (or any other open source C++ compiler for that matter) and just adapt the platform-specifics, but I don't really know about that.
Other than that you can write C code for shit and giggles and just because you can :p
Since the language is simpler, the compilers are faster and produce better code. You can also interface with other languages easily, where in C++ you have to wrap everything in a C ABI before you can do anything.
C++ takes all the lesser points of C and makes them horrible, like using files instead of modules.
It also has facilities for making OOP implementation easier though, and I dislike writing code that low level enough as it is: doing it without the bonus of the standard library and boost sounds like hell to me.
I use GLib quite a bit, adds pretty much anything you need for most development.
[url]http://library.gnome.org/devel/glib/unstable/index.html[/url]
In my personal opinion (:siren: don't get butthurt :siren:) C++ is a horrible language. The syntax is inconsistent as fuck and it feels like a bunch of addons whacked on to C with little thought of how it could be nicely improved.
If only D was practical...
[QUOTE=blankthemuffin;22678627]I use GLib quite a bit, adds pretty much anything you need for most development.[/QUOTE]
I use GLib for [url=http://gitorious.org/dhcpmasqd]a project of mine[/url] and I agree it's pretty nice.
One of the reasons C is more popular than C++ for performance-critical things like OS kernels and embedded systems because it has no "hidden behavior" like C++ does. In a C++ program, something innocuous-looking like a return statement may actually involve multiple implicit function calls, to run the destructors of local variables that are going out of scope. A simple expression like (a+b) might actually invoke an operator+() function that does something complex like memory allocation or network communication. For many applications these features are good because they let us write simpler, more-maintainable code, but for things like OS kernels and embedded systems, they're problematic because time-consuming or thread-unsafe operations may occur in unexpected places. In C, every action the program will take is plainly written in its source code, so it's easier to understand exactly what the program will do at runtime.
[QUOTE=Wyzard;22679274]A simple expression like (a+b) might actually invoke an operator+() function that does something complex like memory allocation or network communication[/QUOTE]
That is a completely BS argument.
If you have a custom operator+(), then you must be dealing with non-primitive types. Which means that in C you wouldn't be able to do a+b anyway, and you'd have to do sometype_add(a, b). And now you're back to square one - what if sometype_add() actually does something complex like memory allocation or network communication?
Any function call can do complex things, of course, and you need to know which functions are safe to call in a critical section and which are not.
The difference is that when you see sometype_add(a, b) it's obvious that a function is [i]being[/i] called, just from looking at that line of code. When you see (a+b) it's not so obvious; you have to look elsewhere to see what the types of a and b are. If templates are involved, they might be template parameters rather than actual types, and then you'd have to search the entire program to find all the types that the template is used with.
C forces you to write code in a way that's more explicit about what it does, rather than relying on implicit things done by the compiler. It's possible to write C++ code in the same way, but it goes against established C++ conventions (smart pointers for memory management, templates for generic algorithms, etc.) and you lose most of the benefits of C++ by doing so.
[QUOTE=blankthemuffin;22678725]If only D was practical...[/QUOTE]
I'm waiting for Go to become an adult.
[QUOTE=Wyzard;22681327]When you see (a+b) it's not so obvious; you have to look elsewhere to see what the types of a and b are.[/QUOTE]
Wait, let me get this right - you're adding two variables, but you have [i]no idea[/i] what types they are? Your argument is flawed. Stop trying to defend it just because you've heard someone else say it.
If only the standards were updated annually and you could select which year your project was built on sorta like how visual studio does .net 1.1/2.0/3.0/3.5/4.
A programmer can dream.
Vala also looks nice: I wonder how cross platform it's ever going to be though...
[QUOTE=nullsquared;22682613]Wait, let me get this right - you're adding two variables, but you have [I]no idea[/I] what types they are? Your argument is flawed. Stop trying to defend it just because you've heard someone else say it.[/QUOTE]
I don't know about you but I don't go through a library I'm using and check up on what EXACTLY the + operator does for a certain class, or their destructor unless I need to know them. So your argument is flawed, the programmer may very well not know what's going on behind the scenes.
If your variables aren't primitive than you obviously know that + will call a function. It's the same thing as calling add(a,b). Both call functions and both functions can do anything behind the scenes.
[QUOTE=Jawalt;22684313]I don't know about you but I don't go through a library I'm using and check up on what EXACTLY the + operator does for a certain class, or their destructor unless I need to know them.[/quote]
Precisely, because you're not the guy optimizing the code, so you don't have the worry. The guy optimizing the code will have to worry about it regardless of whether the function is called add() or operator+().
C is used in microcontroller applications.
[QUOTE=blankthemuffin;22678725]If only D was practical...[/QUOTE]
How come D isn't really being used yet?
[QUOTE=efeX;22688437]How come D isn't really being used yet?[/QUOTE]
Blank just said it's not really practical. You even quoted him!
I asked why........
[QUOTE=nullsquared;22686085]Precisely, because you're not the guy optimizing the code, so you don't have the worry. The guy optimizing the code will have to worry about it regardless of whether the function is called add() or operator+().[/QUOTE]
But when using someone else's library, when I want to be the guy optimizing my code I can actually see myself forgetting all about deconstructors and such.
[QUOTE=Jawalt;22691534]But when using someone else's library, when I want to be the guy optimizing my code I can actually see myself forgetting all about deconstructors and such.[/QUOTE]
In which case you're a terrible optimizer and you should learn to use a profiler, or let someone else do your job.
(Not trying to be mean or anything, just being honest.)
C can also be used for native Python modules.
You can't use a C++ library in Python.
[QUOTE=PvtCupcakes;22693503]C can also be used for native Python modules.
You can't use a C++ library in Python.[/QUOTE]
You can't use a C++ library in anything but C++ anyway.
[QUOTE=nullsquared;22693705]You can't use a C++ library in anything but C++ anyway.[/QUOTE]
Actually you can sometimes access a C++ library from D.
The more you know --==*
[QUOTE=nullsquared;22693446]In which case you're a terrible optimizer and you should learn to use a profiler, or let someone else do your job.
(Not trying to be mean or anything, just being honest.)[/QUOTE]
Or it's just no 'obvious' as he said. There's no obvious function call indicated by a curly bracket.
[QUOTE=Chandler;22694268]Actually you can sometimes access a C++ library from D.
The more you know --==*[/QUOTE]
Keyword: sometimes.
[editline]09:32PM[/editline]
C++'s name mangling is not standard across compilers, that's why its an issue. It's not an issue with the language itself per-se.
Sorry, you need to Log In to post a reply to this thread.