Download C++ Hacker's Guide PDF

TitleC++ Hacker's Guide
File Size23.5 MB
Total Pages231
Table of Contents
                            Real World Hacks
Hack 1: Make Code Disappear
Hack 2: Let Someone Else Write It
Hack 3: Use the const Keyword Frequently For Maximum Protection
Hack 4: Turn large parameter lists into structures
Hack 5: Defining Bits
Hack 6: Use Bit fields Carefully
Hack 7: Documenting bitmapped variables
Hack 8: Creating a class which can not be copied
Hack 9: Creating Self-registering Classes
Hack 10: Decouple the Interface and the Implementation
Hack 11: Learning From The Linux Kernel List Functions
Hack 12: Eliminate Side Effects
Hack 13: Don't Put Assignment Statements Inside Any Other Statements
Hack 14: Use const Instead of #define When Possible
Hack 15: If You Must Use #define Put Parenthesis Around The Value
Hack 16: Use inline Functions Instead of Parameterized Macros Whenever Possible
Hack 17: If You Must Use Parameterized Macros Put Parenthesis Around The arguments
Hack 18: Don't Write Ambiguous Code
Hack 19: Don't Be Clever With the Precedence Rules
Hack 20: Include Your Own Header File
Hack 21: Synchronize Header and Code File Names
Hack 22: Never Trust User Input
Hack 23: Don't use gets
Hack 24: Flush Debugging
Hack 25: Protect array accesses with assert
Hack 26: Use a Template to Create Safe Arrays
Hack 27: When Doing Nothing, Be Obvious About It
Hack 28: End Every Case with break or /* Fall Through */
Hack 29: A Simple assert Statements For Impossible Conditions
Hack 30: Always Check for The Impossible Cases In switches
Hack 31: Create Opaque Types (Handles) Which can be Checked at Compile Time
Hack 32: Using sizeof When Zeroing Out Arrays
Hack 33: Use sizeof(var) Instead of sizeof(type) in memset Calls
Hack 34: Zero Out Pointers to Avoid Reuse
Hack 35: Use strncpy Instead of strcpy To Avoid Buffer Overflows
Hack 36: Use strncat instead of strcat for safety
Hack 37: Use snprintf To Create Strings
Hack 38: Don't Design in Artificial Limits
Hack 39: Always Check for Self Assignment
Hack 40: Use Sentinels to Protect the Integrity of Your Classes
Hack 41: Solve Memory Problems with valgrind
Hack 42: Finding Uninitialized Variables
Hack 29: Valgrind Pronunciation
Hack 43: Locating Pointer problems ElectricFence
Hack 44: Dealing with Complex Function and Pointer Declarations
Hack 45: Create Text Files Instead of Binary Ones Whenever Feasible
Hack 46: Use Magic Strings to Identify File Types
Hack 47: Use Magic Numbers for Binary Files
Hack 48: Automatic Byte Ordering Through Magic Numbers
Hack 49: Writing Portable Binary Files
Hack 50: Make You Binary Files Extensible
Hack 51: Use magic numbers to protect binary file records
Hack 52: Know When to Use _exit
Hack 53: Mark temporary debugging messages with a special set of characters.
Hack 54: Use the Editor to Analyze Log Output
Hack 55: Flexible Logging
Hack 56: Turn Debugging On and Off With a Signal
Hack 57: Use a Signal File to Turn On and Off Debugging
Hack 58: Starting the Debugger Automatically Upon Error
Hack 59: Making assert Failures Start the Debugger
Hack 60: Stopping the Program at the Right Place
Hack 61: Creating Headings within Comment
Hack 62: Emphasizing words within a paragraph
Hack 63: Putting Drawings In Comments
Hack 64: Providing User Documentation
Hack 65: Documenting the API
Hack 66: Use the Linux Cross Reference to Navigate Large Coding Projects
Hack 67: Using the Pre-processor to Generate Name Lists
Hack 68: Creating Word Lists Automatically
Hack 69: Preventing Double Inclusion of Header Files
Hack 70: Enclose Multiple Line Macros In do/while
Hack 71: Use #if 0 to Remove Code
Hack 72: Use #ifndef QQQ to Identify Temporary Code
Hack 73: Use #ifdef on the Function Not on the Function Call to Eliminate Excess #ifdefs
Hack 74: Create Code to Help Eliminate #ifdef Statements From Function Bodies
Hack 75: Don't Use any “Well Known” Speedups Without Verification
Hack 76: Use gmake -j to speed up compilation on dual processor machines
Hack 77: Avoid Recompiling by Using ccache
Hack 78: Using ccache Without Changing All Your Makefiles
Hack 79: Distribute the Workload With distcc
Hack 80: Don't Optimize Unless You Really Need to
Hack 81: Use the Profiler to Locate Places to Optimize
Hack 82: Avoid the Formatted Output Functions
Hack 83: Use ++x Instead of x++ Because It's Faster
Hack 84: Optimize I/O by Using the C I/O API Instead of the C++ One
Hack 85: Use a Local Cache to Avoid Recomputing the Same Result
Hack 86: Use a Custom new/delete to Speed Dynamic Storage Allocation
Anti-Hack 87: Creating a Customized new / delete Unnecessarily
Anti-Hack 88: Using shift to multiple or divide by powers of 2
Hack 89: Use static inline Instead of inline To Save Space
Hack 90: Use double Instead of Float Faster Operations When You Don't Have A Floating Point Processor
Hack 91: Tell the Compiler to Break the Standard and Force it To Treat float as float When Doing Arithmetic
Hack 92: Fixed point arithmetic
Hack 93: Verify Optimized Code Against the Unoptimized Version
Case Study: Optimizing bits_to_bytes
Hack 94:  Designated Structure Initializers
Hack 95: Checking printf style Arguments Lists
Hack 96: Packing structures
Hack 97: Creating Functions Who's Return Shouldn't Be Ignored
Hack 98: Creating Functions Which Never Return
Hack 99: Using the GCC Heap Memory Checking Functions to Locate Errors
Hack 100: Tracing Memory Usage
Hack 101: Generating a Backtrace
Anti-Hack 102: Using “#define extern” for Variable Declarations
Anti-Hack 103: Use , (comma) to join statements
Anti-Hack 104: if (strcmp(a,b))
Anti-Hack 105: if (ptr)
Anti-Hack 106: The “while ((ch = getch()) != EOF)” Hack
Anti-Hack 107: Using #define to Augment the C++ Syntax
Anti-Hack 108: Using BEGIN and END Instead of { and }
Anti-Hack 109: Variable Argument Lists
Anti-Hack 110: Opaque Handles
Anti-Hack 111: Microsoft (Hungarian) Notation
Hack 112: Always Verify the Hardware Specification
Hack 113: Use Portable Types Which Specify Exactly How Wide Your Integers Are
Hack 114: Verify Structure Sizes
Hack 115: Verify Offsets When Defining the Hardware Interface
Hack 116: Pack Structures To Eliminate Hidden Padding
Hack 117: Understand What the Keyword volatile Does and How to Use It.
Hack 118: Understand What the Optimizer Can Do To You
Hack 119: In Embedded Programs, Try To Handle Errors Without Stopping
Hack 120: Detecting Starvation
Hack 121: Turning on Syntax Coloring
Hack 122: Using Vim's internal make system
Hack 123: Automatically Indenting Code
Hack 124: Indenting Existing Blocks of Code
Hack 125: Use tags to Navigate the Code
Hack 126: You Need to Find the Location of Procedure for Which You Only Know Part of the Name
Hack 127: Use :vimgrep to Search for Variables or Functions
Hack 128: Viewing the Logic of Large Functions
Hack 129: View Logfiles with Vim
Hack 130: Flipping a Variable Between 1 and 2
Hack 131: Swapping Two Numbers Without a Temporary
Hack 132: Reversing the Words In a String Without a Temporary
Hack 133: Implementing a Double Linked List with a Single Pointer
Hack 134: Accessing Shared Memory Without a Lock
Hack 135: Answering the Object Oriented Challenge
Grace Hopper
Linus Torvalds
Using the letters O, l, I as variable names
Not Sharing Your Work
No Comments
IncOnsisTencY
Duplicating Code (Programming by Cut and Paste)
ctags – Function Indexing System
doxygen
FlawFinder
gcc – The GNU C and C++ compiler suite
lxr
Perl (for perldoc and related tools) – Documentation System
valgrind (memory checking tools)
Vim (Vi Improved)
	License
	Creative Commons Notice
                        

Similer Documents