LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-03-2015, 02:14 PM   #1
Borneq
Member
 
Registered: Aug 2014
Posts: 36

Rep: Reputation: Disabled
Why low-level libraries uses C ?


why not C++? For example XLib, XCB.
C++ libraries will difficult to link with next level libraries?
 
Old 12-03-2015, 02:17 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 3,137

Rep: Reputation: 855Reputation: 855Reputation: 855Reputation: 855Reputation: 855Reputation: 855Reputation: 855
Because C++ is a higher level library than C, and has a lot more overhead when compiling/running.
 
Old 12-03-2015, 06:17 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
... and of course, C came first.

In fact the Unix OS (& derivatives) & most DBs and higher level langs are written in C.
Therefore the libs can be used by the max number of programs.
 
Old 12-03-2015, 06:32 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,610
Blog Entries: 4

Rep: Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905
Either language can be used, and both have been. There are some libraries that are written in FORTRAN.
 
Old 12-03-2015, 07:31 PM   #5
Borneq
Member
 
Registered: Aug 2014
Posts: 36

Original Poster
Rep: Reputation: Disabled
C++ is handy, but how C++ libraries can be used by other programs? Especially inline, templates, name mangling, virtual methods.
 
Old 12-03-2015, 09:06 PM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,852
Blog Entries: 1

Rep: Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868
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.
 
Old 12-05-2015, 11:32 AM   #7
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
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.
 
Old 12-05-2015, 11:41 AM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,852
Blog Entries: 1

Rep: Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868
If Microsoft didn't have a C-compiler, how could they compile Windows?
 
Old 12-05-2015, 12:05 PM   #9
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Quote:
Originally Posted by NevemTeve View Post
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


http://herbsutter.com/2012/05/03/rea...ut-vc-and-c99/
Quote:
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?
 
Old 12-05-2015, 12:15 PM   #10
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,852
Blog Entries: 1

Rep: Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868
(I have to admit that in Windows I use either BCC4.52 (16-bit) or BCC55 (32-bit) or mingw-gcc (64-bit).)
 
Old 12-06-2015, 10:08 AM   #11
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,610
Blog Entries: 4

Rep: Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905
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.
 
Old 12-07-2015, 06:31 AM   #12
Luridis
Member
 
Registered: Mar 2014
Location: Texas
Distribution: LFS 9.0 Custom, Merged Usr, Linux 4.19.x
Posts: 616

Rep: Reputation: 167Reputation: 167
"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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Interrupts low level elico Linux - Hardware 1 02-19-2012 09:14 AM
[SOLVED] 0/Low level format varunb Linux - Newbie 11 08-26-2011 02:38 AM
low level languages devit Programming 2 05-07-2004 11:16 AM
Low level formatting.... Santorres Linux - General 1 02-02-2004 07:50 AM
low level formatting? hyperpimp Linux - Newbie 16 04-13-2002 12:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration