Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C WikiBooks - How is C a small "what you see is all you get" language?

Tags:

c

I'm unable to understand one of the following sentence from WikiBooks :

Why C, and not assembly language?

" C is a compiled language, which creates fast and efficient executable files. It is also a small "what you see is all you get" language: a C statement corresponds to at most a handful of assembly statements, everything else is provided by library functions. "


Website Link : C Programming/Why learn C? - Wikibooks, open books for an open world

Note : I am a complete beginner and I've started to learn C . So, I need a precise explanation of what the above sentence means.

like image 852
Harish Raja Avatar asked Dec 02 '22 13:12

Harish Raja


2 Answers

The assembly is the language for a single processor family, it is directly compiled to the machine code that the processor runs. If one programs in assembly, one needs to rewrite the entire code for the different processor family. Phones usually use ARM processors whereas the desktop computers have 32-bit or 64-bit x86-compatible processors. Each 3 of these potentially need a completely separately written program, and perhaps not even limited to that.

In contrast standard C is a portable language - if you write so-called strictly conforming programs. C11 4p5:

A strictly conforming program shall use only those features of the language and library specified in this International Standard. (3) It shall not produce output dependent on any unspecified, undefined, or implementation-defined behavior, and shall not exceed any minimum implementation limit.

With footnote 5 noting that:

Strictly conforming programs are intended to be maximally portable among conforming implementations. Conforming programs may depend upon nonportable features of a conforming implementation

Unlike the assembler whose specifics vary from processor to another, it is possible to write programs in C and then port them to various platforms without any changes into the source code, yet these programs will still be compiled into the assembly language, and performance could - and often will - surpass hand-written assembly when using a modern high-quality optimizing compiler.

Additionally the C standard library, which any conforming hosted implementation needs to provide, provides for a portable way to manage files, dynamic memory, input and output, all of which are not only processor but also operating-system specific when using assembler.

However, C is still quite close to the assembly, to the extent that it has been called a "high-level assembly language" by some.


It makes no sense to say compiled language and interpreted language.

This kind of statement are made by persons without education and could not understand the foundations of programming.

A language is defined mathematically via a way to define languages -- operational, denotational, axiomatic, etc and the programmers implement the language as they wish.

There are machines that run C via interpretation, they dispatch the code at the moment of execution and execute it instead of accumulating some object code that would be executed later by some machine, etc.

It is correct to say compiled implementation, interpreted implementation for the language, but even so it is relative to a given machine. Because when you compile it for x86 processors, the compiled code is interpreted by the datapath and controller of a stack machine for the X86 language, etc.

Basically the statement what you see is all you get means that is almost 1 to 1 correspondence between the operators of the CAM defined in the abstract semantics of ISO 9899 and the current stack-machines on the market, like x86, mips, etc.

like image 22
alinsoar Avatar answered Jan 30 '23 08:01

alinsoar