Extreme C: Taking You To The Limit In Concurrency, OOP, And The Most Advanced Capabilities Of C

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

There’s a lot more to C than knowing the language syntax. The industry looks for developers with a rigorous, scientific understanding of the principles and practices. Extreme C will teach you to use C’s advanced low-level power to write effective, efficient systems. This intensive, practical guide will help you become an expert C programmer.

Author(s): Kamran Amini
Publisher: Packt Publishing
Year: 2019

Language: English
Pages: 823
Tags: C Programming

Cover......Page 1
Copyright......Page 3
packt Page......Page 4
Contributors......Page 5
Table of Contents......Page 8
Preface......Page 18
Chapter 01: Essential Features......Page 28
Preprocessor directives......Page 30
Macros......Page 31
Defining a macro......Page 32
Variadic macros......Page 39
Advantages and disadvantages of macros......Page 43
Conditional compilation......Page 46
Syntax......Page 49
Arithmetic on variable pointers......Page 51
Generic pointers......Page 55
Dangling pointers......Page 58
Anatomy of a function......Page 61
Importance in design......Page 62
Pass-by-value versus pass-by-reference......Page 63
Function pointers......Page 66
Structures......Page 68
Why user-defined types?......Page 69
Memory layout......Page 71
Nested structures......Page 76
Structure pointers......Page 77
Summary......Page 78
Chapter 02: From Source to Binary......Page 80
Compilation pipeline......Page 81
Header files versus source files......Page 83
Example source files......Page 86
Building the example......Page 88
Step 1 – Preprocessing......Page 90
Step 2 – Compilation......Page 92
Step 3 – Assembly......Page 96
Supporting new architectures......Page 99
Step details......Page 100
Preprocessor......Page 102
Compiler......Page 106
Abstract syntax tree......Page 107
Assembler......Page 109
Linker......Page 110
How does the linker work?......Page 111
Linker can be fooled!......Page 120
C++ name mangling......Page 125
Summary......Page 127
Chapter 03: Object Files......Page 128
Application binary interface (ABI)......Page 129
Object file formats......Page 131
Relocatable object files......Page 132
Executable Object Files......Page 137
Static libraries......Page 142
Dynamic libraries......Page 151
Manual loading of shared libraries......Page 156
Summary......Page 158
Chapter 04: Process Memory Structure......Page 160
Process memory layout......Page 161
Discovering memory structure......Page 162
Probing static memory layout......Page 163
BSS segment......Page 165
Data segment......Page 168
Text segment......Page 172
Probing dynamic memory layout......Page 174
Memory mappings......Page 175
Stack segment......Page 180
Heap segment......Page 181
Summary......Page 185
Chapter 05: Stack and Heap......Page 188
Stack......Page 189
Probing the Stack......Page 190
Points on using the Stack memory......Page 197
Heap......Page 202
Heap memory allocation and deallocation......Page 203
Heap memory principles......Page 213
Memory management in constrained environments......Page 217
Memory-constrained environments......Page 218
External data storage......Page 219
Caching......Page 220
Allocation and deallocation cost......Page 225
Summary......Page 226
Chapter 06: OOP and Encapsulation......Page 228
Object-oriented thinking......Page 230
Mental concepts......Page 231
Mind maps and object models......Page 233
Objects are not in code......Page 235
Object attributes......Page 236
Relations among objects......Page 237
Object-oriented operations......Page 238
Objects have behaviors......Page 241
C is not object-oriented, but why?......Page 242
Attribute encapsulation......Page 243
Behavior encapsulation......Page 246
Information hiding......Page 257
Summary......Page 264
Relations between classes......Page 266
Object versus class......Page 267
Composition......Page 269
Aggregation......Page 276
Summary......Page 283
Chapter 08: Inheritance and Polymorphism......Page 284
Inheritance......Page 285
The nature of inheritance......Page 286
The first approach for having inheritance in C......Page 288
The second approach to inheritance in C......Page 295
Comparison of two approaches......Page 301
Polymorphism......Page 302
What is polymorphism?......Page 303
Why do we need polymorphism?......Page 306
How to have polymorphic behavior in C......Page 307
Summary......Page 315
Abstraction......Page 316
Encapsulation......Page 320
Inheritance......Page 324
Polymorphism......Page 331
Abstract classes......Page 334
Summary......Page 335
Chapter 10: Unix – History and Architecture......Page 336
Multics OS and Unix......Page 337
BCPL and B......Page 339
The way to C......Page 340
Unix architecture......Page 341
Philosophy......Page 342
Unix onion......Page 344
Shell interface to user applications......Page 346
Kernel interface to shell ring......Page 351
Kernel......Page 358
Hardware......Page 362
Summary......Page 364
System calls......Page 366
System calls under the microscope......Page 367
Bypassing standard C – calling a system call directly......Page 368
Inside the syscall function......Page 371
Kernel development......Page 373
Writing a Hello World system call for Linux......Page 375
Building the kernel......Page 382
Unix kernels......Page 388
Monolithic kernels versus microkernels......Page 389
Linux......Page 390
Kernel modules......Page 391
Adding a kernel module to Linux......Page 392
Summary......Page 398
Chapter 12: The Most Recent C......Page 400
Finding a supported version of C standard......Page 401
Removal of the gets function......Page 403
Changes to fopen function......Page 404
Bounds-checking functions......Page 405
No-return functions......Page 406
Type generic macros......Page 407
Unicode......Page 408
Anonymous structures and anonymous unions......Page 415
Summary......Page 417
Chapter 13: Concurrency......Page 418
Introducing concurrency......Page 419
Parallelism......Page 420
Concurrency......Page 421
Task scheduler unit......Page 422
Processes and threads......Page 424
Happens-before constraint......Page 425
When to use concurrency......Page 427
Shared states......Page 434
Summary......Page 439
Concurrency issues......Page 440
Intrinsic concurrency issues......Page 442
Post-synchronization issues......Page 452
Synchronization techniques......Page 453
Busy-waits and spin locks......Page 454
Sleep/notify mechanism......Page 457
Semaphores and mutexes......Page 461
Multiple processor units......Page 466
Spin locks......Page 470
Condition variables......Page 472
Concurrency in POSIX......Page 473
Kernels supporting concurrency......Page 474
Multi-processing......Page 476
Multithreading......Page 479
Summary......Page 480
Chapter 15: Thread Execution......Page 482
Threads......Page 484
POSIX threads......Page 487
Spawning POSIX threads......Page 488
Example of race condition......Page 494
Example of data race......Page 503
Summary......Page 506
Chapter 16: Thread Synchronization......Page 508
POSIX mutexes......Page 509
POSIX condition variables......Page 512
POSIX barriers......Page 516
POSIX semaphores......Page 519
POSIX threads and memory......Page 527
Stack memory......Page 528
Heap memory......Page 533
Memory visibility......Page 538
Summary......Page 540
Process execution APIs......Page 542
Process creation......Page 545
Process execution......Page 550
Comparing process creation and process execution......Page 553
Process execution steps......Page 554
Sharing techniques......Page 555
POSIX shared memory......Page 557
Data race example using shared memory......Page 563
File system......Page 568
Multithreading......Page 570
Single-host multi-processing......Page 571
Distributed multi-processing......Page 572
Summary......Page 573
Chapter 18: Process Synchronization......Page 574
Single-host concurrency control......Page 575
Named POSIX semaphores......Page 576
The first example......Page 580
The second example......Page 584
Step 1 – Global declarations......Page 585
Step 2 – Cancellation flag's shared memory......Page 586
Step 3 – Named mutex's shared memory......Page 589
Step 4 – Setting the cancellation flag......Page 591
Step 5 – The main function......Page 592
Named condition variables......Page 595
Step 1 – Class of shared memory......Page 596
Step 2 – Class of shared 32-bit integer counter......Page 599
Step 3 – Class of shared mutex......Page 601
Step 4 – Class of shared condition variable......Page 604
Step 5 – The main logic......Page 608
Distributed concurrency control......Page 614
Summary......Page 616
Chapter 19: Single-Host IPC and Sockets......Page 618
IPC techniques......Page 619
Communication protocols......Page 621
Protocol characteristics......Page 623
Length of messages......Page 624
Sequentiality......Page 625
File descriptors......Page 626
POSIX signals......Page 627
POSIX pipes......Page 631
POSIX message queues......Page 633
Introduction to socket programming......Page 637
Physical layer......Page 638
Link layer......Page 639
Network layer......Page 640
Transport layer......Page 644
Application layer......Page 649
Internet protocol suite......Page 650
What is a socket?......Page 651
POSIX socket library......Page 652
Sockets have their own descriptors!......Page 657
Summary......Page 658
Chapter 20: Socket Programming......Page 660
Socket programming review......Page 661
Calculator project......Page 663
Source hierarchy......Page 664
Run the project......Page 668
Application protocol......Page 669
Serialization/deserialization library......Page 673
Server-side serializer/deserializer functions......Page 675
Client-side serializer/deserializer functions......Page 677
Calculator service......Page 678
UDS stream server......Page 680
UDS stream client......Page 688
UDS datagram server......Page 691
UDS datagram client......Page 696
TCP server......Page 698
TCP client......Page 699
UDP server......Page 701
The UDP client......Page 702
Summary......Page 703
Chapter 21: Integration with Other Languages......Page 704
Why integration is possible?......Page 705
Obtaining the necessary materials......Page 706
Stack library......Page 707
Name mangling in C++......Page 714
C++ code......Page 716
Writing the Java part......Page 722
Writing the native part......Page 727
Integration with Python......Page 735
Integration with Go......Page 739
Summary......Page 742
Chapter 22: Unit Testing and Debugging......Page 744
Software testing......Page 745
Unit testing......Page 747
Test doubles......Page 755
Component testing......Page 756
Testing libraries for C......Page 758
CMocka......Page 759
Google Test......Page 769
Debugging......Page 773
Bug categories......Page 775
Debuggers......Page 776
Memory checkers......Page 777
Thread debuggers......Page 779
Performance profilers......Page 780
Summary......Page 781
Chapter 23: Build Systems......Page 782
What is a build system?......Page 783
Make......Page 784
CMake – not a build system!......Page 792
Ninja......Page 798
Bazel......Page 800
Comparing build systems......Page 803
Summary......Page 804
Other Books You May Enjoy......Page 806
Index......Page 810