ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If a component (library) is written in C++, its caller has to be written in C++, too. On the other hand, C components can be called from C++ without problems.
C was here first, it was invented to write Unix, so Unix is C.
C it has a standard ABI in opposite for example to C++.
it is relatively easy to include into other languages, in opposite to say C++, which is complex.
in the Unix world C is the lingua franca, you cann connect different programming languages via C interfaces.
Microsoft on the other hand does not even have a real C compiler, there you write your drivers with C++ base on a unbelievable ugly old style Cish interface.
If Microsoft didn't have a C-compiler, how could they compile Windows?
with the compiler they have, since C is a valid subset of C++ (99.9%), they can compile their C like code with their compilers. Thought, I think they have 2 different runtime libraries to link again. And maybe there is a old compiler, but I do not thing anyone uses this, if you compile python ruby whatever on MS they want MSVC
We recommend that C developers use the C++ compiler to compile C code (using /TP if the file is named something.c). This is the best choice for using Visual C++ to compile C code.
there is no problem with this, Haiku OS is an other example where the kernel is written in C++.
why should this be a problem?
Different parts of Microsoft's total software system are obviously written in many different languages.
"C" is ordinarily used in operating-system code because languages like "C++" rely upon services provided by runtime libraries which only exist "in user-land." In this context, "C" is being used as "one small step up from assembler," and in fact is often intermingled with assembler-code sections. (The "trampoline" code in the /arch directory of the Linux source library is an excellent example of this. Some of the files there are pure-assembler files.)
Higher-level languages are used whenever possible, and when a legacy source-code base that was originally started in "C" does not exist. That's because, well, "because the language system is doing more of the niggling detail-work for you," and, "that's what digital computers are for!"
There's little difference in the actual object-code that is generated. In the gcc compiler suite, most of the back-end code generation code does not care what source-code language was originally used. It's working with an intermediate representation that is more or less source-language agnostic.
Last edited by sundialsvcs; 12-06-2015 at 10:09 AM.
Distribution: LFS 9.0 Custom, Merged Usr, Linux 4.19.x
Posts: 616
Rep:
"C" is the hardware interface language. It's not about catering to the upward needs of the software stack. It's about talking to hardware in a predictable way. It's at this level almost all algorithms need to be checked for efficiency, be the efficiency in power, performance, or heat generation. For every run of your program's main loop, no-ops can happen low in the system millions of times. Hence why they calculus is still required for "Computer Systems Engineering", even though it's typically unnecessary for what most of us would consider programming.
Here is a video of Linus Torvalds discussing just this subject at a Q&A.
Knowing the language can help you a lot. However, writing everyday programs in C is typically unnecessary, or even dangerous if you were to publish code you are unwilling or unable to check for unsafe practices. For that reason, lots of people like to complain about the language's lack of exception handling. The reality is that it is simply not supposed to be there. Handling exceptions creates lots of overhead at the assembly level. It's the high-level application developers job to check input before passing it to some part of the system. I mean, if you're the one asking for input, it's not the libc developer's job to make sure it's well formed before trying to operate on the data, it's yours.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.