Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use C? [closed]

Tags:

c

Why is C used for writing drivers and OS codes?

Is there a size problem?

Are there any drivers written in other languages?

Which language were XP, Vista, and Solaris written in?

like image 456
Renjith G Avatar asked Jun 12 '09 03:06

Renjith G


1 Answers

In safety-critical environments (think avionics, spacecraft, medical devices, transportation, control software for process control), systems (as well as drivers) are often written using Ada or even SPARK/Ada.

To clarify: C is usually understood to be fairly low level, and pretty much like a "macro language" for assembly itself, that's also where its power is coming from (speed, size, portability).

Ada, on the other, hand has been specifically designed for safety-critical applications with verifiability in mind, to quote Ada 2005 for Mission-Critical Systems:

Ada [9] is the language of choice for many critical systems due to its careful design and the existence of clear guidelines for building high integrity systems [10]

That's also where Ada's support for strong typing comes in, as well as a number of other important features (quoting design for safety):

Programming languages differ wildly in their appropriateness for use in safetyrelated systems. Carré et al. identified six factors that influence the suitability of a language for high-integrity applications [Carré 1990]. These are:

  • Logical soundness
  • Complexity of definition
  • Expressive power
  • Security
  • Verifiability
  • Bounded time and space constraints

No standard programming language performs well in all these areas although some (such as Pascal and Ada) perform much better than languages such as C or C++. In highly critical applications ‘verifiability’ is of great importance. Certain languages allow powerful software verification tools to be used to perform a wide range of static tests on the code to detect a range of programming errors. [...] An important issue in the selection of a programming language is the quality of the available compilers and other tools. For certain languages validated compilers are available. While not guaranteeing perfection, validation greatly increasing our confidence in a tool. Unfortunately, validated compilers are only available for a limited number of languages, such as Ada and Pascal. In addition to compilers, developers of critical systems will make use of a range of other tools such as static code analysis packages. The static tests that can be performed on a piece of code vary greatly depending on the language used. To aid this process it is common to restrict the features that are used within certain languages to a ‘safe subset’ of the language. Well structured and defined languages such as subsets of Ada, Pascal and Modula-2 allow a great many tests to be performed such as data flow analysis, data use analysis, information flow analysis and range checking. Unfortunately many of these tests cannot be performed on languages such as C and C++ .

It would be really beyond the scope of this question to go into even more detail, but you may want to check out some of the following pointers:

  • Ada compared to C and C++
  • Ada vs. C
  • Quantifying the Debate: Ada vs. C++
  • Why choosing Ada as a teaching language? (Ada vs. C in University)
  • Comparing Development Costs of C and Ada (summary)
  • C / C++ / Java Pitfalls & Ada Benefits
  • Is Ada a better C?
  • Ada, C, C++, and Java vs. The Steelman
  • Ada: Dispelling the Myths
  • Real-time programming safety in Java and Ada

If anyone wants to look into Ada some more, check out this: Ada Programming (wikibooks)

There are even programming languages that are specifically developed for highly critical applications, such as JOVIAL or HAL/S, the latter of which is used by the space shuttle program.

Is there any drivers written in any other languages?

I have seen some Linux drivers for special hardware being written in Ada, don't know about other operating systems though. However, such drivers usually end up wrapping the the C API.

like image 125
none Avatar answered Sep 20 '22 09:09

none