Home > Work > Expert C Programming: Deep C Secrets
1 " The keyword const doesn’t turn a variable into a constant! A symbol with the const qualifier merely means that the symbol cannot be used for assignment. This makes the value read-only through that symbol ; it does not prevent the value from being modified through some other means internal (or even external) to the program. "
― , Expert C Programming: Deep C Secrets
2 " You can count in binary on your fingers up to 1023. "
3 " When the ANSI C standard was under development, the pragma directive was introduced. Borrowed from Ada, #pragma is used to convey hints to the compiler, such as the desire to expand a particular function in-line or suppress range checks. Not previously seen in C, pragma met with some initial resistance from a gcc implementor, who took the “implementation-defined” effect very literally—in gcc version 1.34, the use of pragma causes the compiler to stop compiling and launch a computer game instead! The gcc manual contained the following: The “#pragma” command is specified in the ANSI standard to have an arbitrary implementation-defined effect. In the GNU C preprocessor, “#pragma” first attempts to run the game “rogue”; if that fails, it tries to run the game “hack”; if that fails, it tries to run GNU Emacs displaying the Tower of Hanoi; if that fails, it reports a fatal error. In any case, preprocessing does not continue. —Manual for version 1.34 of the GNU C compiler "
4 " Never forget that when you point the finger at someone, three of your own fingers are pointing back at you... "
5 " Abstraction is the notion of looking at a group of “somethings” (such as cars, invoices, or executing computer programs) and realizing that they have common themes. You can then ignore the unimportant differences and just record the key data items that characterize the thing (e.g., license number, amount due, or address space boundaries). When you do this, it is called “abstraction”, and the types of data that you store are “abstract data types”. Abstraction sounds like a tough mathematical concept, but don’t be fooled—it’s actually a simplification. "
6 " Abstraction is useful in software because it allows the programmer to: • hide irrelevant detail, and concentrate on essentials. • present a “black box” interface to the outside world. The interface specifies the valid operations on the object, but does not indicate how the object will implement them internally. • break a complicated system down into independent components. This in turn localizes knowledge, and prevents undisciplined interaction between components. • reuse and share code. "
7 " When Arrays Are Pointers The C standard has the following to say about the matter. Rule 1. An array name in an expression (in contrast with a declaration) is treated by the compiler as a pointer to the first element of the array1 (paraphrase, ANSI C Standard, paragraph 6.2.2.1). 1. OK nitpickers, there are a few minuscule exceptions that concern arrays treated as a whole. A reference to an array is not replaced by a pointer to the first element when: • the array appears as the operand of sizeof()—-obviously you want the size of the whole array here, not just a pointer to it. • the array’s address is taken with the & operator. • the array is a string or wide-string literal initializer. Rule 2. A subscript is always equivalent to an offset from a pointer (paraphrase, ANSI C Standard, paragraph 6.3.2.1). Rule 3. An array name in the declaration of a function parameter is treated by the compiler as a pointer to the first element of the array (paraphrase, ANSI C Standard, paragraph 6.7.1). "