Книга: Fedora™ Unleashed, 2008 edition
Programming in C/C++ with Linux
Programming in C/C++ with Linux
C is the programming language most frequently associated with Unix-like operating systems such as Linux or BSD. Since the 1970s, the bulk of the Unix operating system and its applications have been written in C. Because the C language doesn't directly rely on any specific hardware architecture, Unix was one of the first portable operating systems. In other words, the majority of the code that makes up Unix doesn't know and doesn't care on which computer it is actually running. Machine-specific features are isolated in a few modules within the Unix kernel, which makes it easy for you to modify them when you are porting to different hardware architectures.
C is a compiled language, which means that your C source code is first analyzed by the preprocessor. It is then translated into assembly language and then into machine instructions that are appropriate to the target CPU. An assembler then creates a binary, or object, file from the machine instructions. Finally, the object file is linked to any required external software support by the linker. A C program is stored in a text file that ends with a .c
extension and always contains at least one routine, or function, such as main()
, unless the file is an include file (with an .h
extension — also known as a header file) containing shared variable definitions or other data or declarations. Functions are the commands that perform each step of the task that the C program was written to accomplish.
NOTE
The Linux kernel is mostly written in C, which is why Linux works with so many different CPUs. To learn more about building the Linux kernel from source, see Chapter 36, "Kernel and Module Management."
C++ is an object-oriented extension to C. Because C++ is a superset of C, C++ compilers compile C programs correctly, and it is possible to write non-object-oriented code in C++. The reverse is not true: C compilers cannot compile C++ code.
C++ extends the capabilities of C by providing the necessary features for object-oriented design and code. C++ also provides some features, such as the capability to associate functions with data structures, that do not require the use of class-based object-oriented techniques. For these reasons, the C++ language enables existing Unix programs to migrate toward the adoption of object orientation over time.
Support for C++ programming using Fedora is provided by gcc
, which you run with the name g++ when you are compiling C++ code.
- Листинг 10.1. (simpleid.c) Отображение идентификаторов пользователя и группы
- 8.5.2 Typical Condition Variable Operations
- 4.4.4 The Dispatcher
- 3.3.4 init.c
- Introduction to Microprocessors and Microcontrollers
- Project PDL
- 3.2.1.2. Начальное выделение памяти: malloc()
- PART V Programming Linux
- Programming in C
- Using the C Programming Project Management Tools Provided with Fedora Linux
- 14.4.1. Programming Flash Using a JTAG Probe
- 3.2 PIC Microcontroller Input-Output Port Programming