Expert C Programming. Deep C Secrets. Peter van der Linden. SunSoft Press A Prentice Hall Title

Similar documents
KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Glossary of Object Oriented Terms

C++FA 5.1 PRACTICE MID-TERM EXAM

Course Title: Software Development

C++ INTERVIEW QUESTIONS

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

The C Programming Language course syllabus associate level

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

Object Oriented Software Design II

CEC225 COURSE COMPACT

Fundamentals of Java Programming

Java (12 Weeks) Introduction to Java Programming Language

WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt

I Control Your Code Attack Vectors Through the Eyes of Software-based Fault Isolation. Mathias Payer, ETH Zurich

Astro Space Center. Profsoyuznaya st., 84/32 Moscow, Russia, USSR. FAX: PHONE: ikimaileesoci..

Java Interview Questions and Answers

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Semester Review. CSC 301, Fall 2015

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

An Introduction to Programming and Computer Science

The programming language C. sws1 1

C Interview Questions

C++ Programming Language

El Dorado Union High School District Educational Services

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology)

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

Domains and Competencies

Elemental functions: Writing data-parallel code in C/C++ using Intel Cilk Plus

Embedded Software development Process and Tools: Lesson-4 Linking and Locating Software

Sources: On the Web: Slides will be available on:

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

THE OPEN UNIVERSITY OF TANZANIA

Classes and Pointers: Some Peculiarities (cont d.)

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Programming Language Pragmatics

Semantic Analysis: Types and Type Checking

C# Cookbook. Stephen Teilhet andjay Hilyard. O'REILLY 8 Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo '"J""'

Getting Started with the Internet Communications Engine

Chapter 5 Names, Bindings, Type Checking, and Scopes

Object Oriented Programming With C++(10CS36) Question Bank. UNIT 1: Introduction to C++

Objectif. Participant. Prérequis. Remarque. Programme. C# 3.0 Programming in the.net Framework. 1. Introduction to the.

Course MS10975A Introduction to Programming. Length: 5 Days

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

Syllabus for CS 134 Java Programming

Lecture 22: C Programming 4 Embedded Systems

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Java Application Developer Certificate Program Competencies

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.

Tutorial on C Language Programming

: provid.ir

The System Designer's Guide to VHDL-AMS

InterBase 6. Embedded SQL Guide. Borland/INPRISE. 100 Enterprise Way, Scotts Valley, CA

MPLAB TM C30 Managed PSV Pointers. Beta support included with MPLAB C30 V3.00

Memory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation

OKLAHOMA SUBJECT AREA TESTS (OSAT )

Android Application Development Course Program

Virtual vs Physical Addresses

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism

IS0020 Program Design and Software Tools Midterm, Feb 24, Instruction

The Designer's Guide to VHDL

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example

Programming and Software Development (PSD)

Java SE 8 Programming

Semantic Checker (Part I)

Memory Management Outline. Background Swapping Contiguous Memory Allocation Paging Segmentation Segmented Paging

An Overview of Java. overview-1

OpenACC 2.0 and the PGI Accelerator Compilers

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Professional. SlickEdif. John Hurst IC..T...L. i 1 8 О 7» \ WILEY \ Wiley Publishing, Inc.

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

C#5.0 IN A NUTSHELL. Joseph O'REILLY. Albahari and Ben Albahari. Fifth Edition. Tokyo. Sebastopol. Beijing. Cambridge. Koln.

1 Abstract Data Types Information Hiding

Evolution of the Major Programming Languages

MA-WA1920: Enterprise iphone and ipad Programming

Crash Course in Java

Know or Go Practical Quest for Reliable Software

An Incomplete C++ Primer. University of Wyoming MA 5310

Common Beginner C++ Programming Mistakes

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE. CISY 105 Foundations of Computer Science

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example

Delphi Developer Certification Exam Study Guide

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

BCS2B02: OOP Concepts and Data Structures Using C++

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

ADVANCED SCHOOL OF SYSTEMS AND DATA STUDIES (ASSDAS) PROGRAM: CTech in Computer Science

5 Arrays and Pointers

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding

Software Performance and Scalability

Top 10 Bug-Killing Coding Standard Rules

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

The Data Access Handbook

Next, the driver runs the C compiler (cc1), which translates main.i into an ASCII assembly language file main.s.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

A deeper look at Inline functions

Transcription:

Expert C Programming Deep C Secrets Peter van der Linden SunSoft Press A Prentice Hall Title

Contents Preface Xiii Acknowledgments xv Introduction xix The $20 Million Bug xx Converdi on xxi Some Light Relief Turüng File Systems xxii 1. C Through the Mists of Time 1 The Prehistory of C 1 Early Experiences with C 4 The Standard I/O Library and C Preprocessor 6 K&R C 9 The Present Day: ANSI C 11 It's Nice, but Is lt Standard? 14 Translation Limits 16 The Structure of the ANSI C Standard 17 Reading the ANSI C Standard for Fun, Pleasure, and Profit 22 How Quiet is a "Quiet Change"? 25 Some Light Relief The Implementation-Defined Effects of Pragmas. 29 2. It's Not a Bug, It's a Language Feature 31 Why Language Features Matter The Way the Fortran Bug Really Happened! 31 Sins of Commission 33 Switches Let You Down with Fall Through 33 Available Hardware 1s a Crayon? 39 Too Much Default Visibility 41 Sins of Mission 42 Overloading the Camel's Back 42 "Some of the Operators Have the Wrong Precedence" 44 The Early Bug gets() the Internet Worm 48 vii

viii Sins of Omission 50 Mail Won't Go to Users with an "f" in Their Usemames 50 Space The Final Frontier 53 A Digression into C++ Comments 55 The Compiler Date Is Corrupted 55 Lint Should Never Have Been Separated Out 59 Some Light Relief Some Features Really Are Bugs! 60 References 62 3. Unscrambling Deciarations in C 63 Syntax Only a Compiler Could Love 64 How a Declaration Is Formed 66 A Word About structs 68 A Word About unions 71 A Word About enums 73 The Precedence Rule 74 Unscrambling C Declarations by Diagram 75 typedef Can Be Your Friend 78 Difference Between typedef int x (101 and Menne x int[10] 80 What typedef struct foo { foo foo; Means 81 The Piece of Code that Understandeth All Parsing 83 Further Reading 86 Some Light Relief Software to Bite the Wax Tadpole... 86 4. The Shocking Truth: C Arrays and Pointers Are NOT the Same! 95 Arrays Are NOT Pointers! 95 Why Doesn't My Code Work? 96 What's a Declaration? What's a Definition? 97 How Arrays and Pointers Are Accessed 98 What Happens When You "Define as Array/Declare as Pointer" 101 Match Your Declarations to the Definition 102 Other Differences Between Arrays and Pointers 103 Some Light Relief Fun with Palindromes! 105 5. Thinking of Linking 109 Libraries, Linking, and Loading 110 Where the Linker Is in the Phases of Compilation 110 The Benefits of Dynamic Linking 113

ix Five Special Secrets of Linking with Libraries 118 Watch Out for Interpositioning 123 Generating Linker Report Files 128 Some Light Relief Look Who's Talking: Challenging the Turing Test 129 Eliza 130 Eliza Meets the VP 130 Doctor, Meet Doctor 131 The Prize in Boston 133 Conclusions 133 Postscript 135 Further Reading 135 6. Poetry in Motion: Runtime Data Structures 137 a.out and a.out Folklore 138 Segments 139 What the OS Does with Your a.out 142 What the C Runtime Does with Your a.out 145 The Stack Segment 145 What Happens When a Function Gets Called: The Procedure Activation Record 146 The auto and static keywords 151 A Stack Frame Might Not Be on the Stack 152 Threads of Control 152 setjmp and longjmp 153 The Stack Segment Under UNIX 155 The Stack Segment Under MS-DOS 156 Helpful C Tools 156 Some Light Relief Prograrnming Puzzles at Princeton 161 For Advanced Students Only 163 7. Thanks for the Memory 165 The Intel 80x86 Family 165 The Intel 808x6 Memory Model and How lt Got That Way 170 Virtual Memory 174 Cache Memory 177 The Data Segment and Heap 181 Memory Leaks 183 How to Check for a Memory Leak 184

Bus Error, Take the Train 187 Bus Error 188 Segmentation Fault 189 Some Light Relief The Thing King and the Paging Garne 195 8. Why Programmers Can't Teil Halloween from Christznas Day 201 The Potrzebie System of Weights and Measures 201 Making a Glyph from Bit Patterns 203 Types Changed While You Wait 205 Prototype Painfulness 207 Where Prototypes Break Down 209 Getting a Char Without a Carriage Return 212 linplementing a Finite State Machine in C 217 Software ls Harder than Hardware! 219 How and Why to Cast 223 Some Light Relief The International Obfuscated C Code Competition 225 9. More about Arrays 239 When an Array Is a Pointer 239 Why the Confusion? 240 Rule 1: An "Array Name in an Expression" Is a Pointer 243 Rule 2: C Treats Array Subscripts as Pointer Offsets 244 Rule 3: An "Array Name as a Function Parameter" Is a Pointer 246 Why C Treats Array Parameters as Pointers 246 How an Array Parameter Is Referenced 247 Indexing a Slice 250 Arrays and Pointers Interchangeability Summary 251 C Has Multidimensional Arrays... 251...But Every Other Language Calls Them "Arrays of Arrays" 251 How Multidimensional Arrays Break into Components 254 How Arrays Are Laid Out in Memory 256 How to Initialize Arrays 257 Some Light Relief Hardware/Software Trade-Offs 260 10. More About Pointers 263 The Layout of Multidimensional Arrays 263 An Array of Pointers Is an "Illiffe Vector" 265 Using Pointers for Ragged Arrays 269 Passing a One-Dimensional Array to a Function 273

xi Using Pointers to Pass a Multidimensional Array to a Function 273 Attempt 2 275 Attempt 3 276 Attempt 4 277 Using Pointers to Return an Array from a Function 277 Using Pointers to Create and Use Dynamic Arrays 280 Some Light Relief The Limitations of Program Proofs 287 Further Reading 291 11.You Know C, So C++ is Easy! 293 Allez-OOP! 293 Abstraction Extracting Out the Essential Characteristics of a Thing 296 Encapsulation Grouping Together Related Types, Data, and Functions 298 Showing Some Class--Giving User-Defined Types the Same Privileges as Predefined Types 299 Availability 301 Declarations 301 How to Call a Method 304 Constructors and Destructors 305 Inheritance Reusing Operations that Are Already Defined 307 Multiple Inheritance Deriving from Two or More Base Classes 311 Overloading Having One Name for the Same Action on Different Types 312 How C++ Does Operator Overloading 313 Input/Output in C++ 314 Polymorphism Runtime Binding 315 Explanation 317 How C++ Does Polymorphism 318 Fancy Pants Polymorphism 319 Other Corners of C++ 320 If I Was Going There, I Wouldn't Start from Here 322 lt May Be Crufty, but It's the Only Garne in Town 325 Some Light Relief The Dead Computers Society 328 Some Final Light Relief Your Certificate of Merit! 330 Further Reading 331 Appendix:Seerets of Programmer Job Interviews 333 Silicon Valley Programmer Interviews 333 How Can You Detect a Cycle in a Linked List? 334 What Are the Different C Increment Statements For? 335

xii How Is a Library Call Different from a System Call? 338 How Is a File Descriptor Different from a File Pointer? 340 Write Some Code to Determine if a Variable Is Signed or Not 341 What Is the Time Complexity of Printing the Values in a Binary Tree? 342 Give Me a String at Random from This File 343 Some Light Relief How to Measure a Building with a Barometer 344 Fueher Reading 346 Index 349