----------------------------------------------------------------------- GCC Primer for Stupid High Energy Physicists ----------------------------------------------------------------------- (Update Record) 1999/06/19 K.Fujii Original version. ----------------------------------------------------------------------- [0] General Rules ----------------------------------------------------------------------- R1: Stick to ANSI C. const Char_t A::kS = "Some string"; // instantiate a string ----------------------------------------------------------------------- [1] How to use initializers ----------------------------------------------------------------------- int a[6] = { [1] = v1, v2, [4] = v4 }; is equivalent to int a[6] = { 0, v1, v2, 0, v4, 0 }; Labeling the elements of an array initializer is especially useful when the indices are characters or belong to an `enum' type. For example: int whitespace[256] = { [' '] = 1, ['\t'] = 1, ['\h'] = 1, ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 }; Use `[FIRST ... LAST] = VALUE' to initialize a range of elements to the same value: int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 }; ----------------------------------------------------------------------- [2] Character constans ----------------------------------------------------------------------- The Character in Constants ================================ You can use the sequence `\e' in a string or character constant to stand for the ASCII character . ----------------------------------------------------------------------- [3] Alignment ----------------------------------------------------------------------- `aligned (ALIGNMENT)' This attribute specifies a minimum alignment for the variable or structure field, measured in bytes. For example, the declaration: int x __attribute__ ((aligned (16))) = 0; causes the compiler to allocate the global variable `x' on a 16-byte boundary. On a 68040, this could be used in conjunction with an `asm' expression to access the `move16' instruction which requires 16-byte aligned operands. You can also specify the alignment of structure fields. For example, to create a double-word aligned `int' pair, you could write: struct foo { int x[2] __attribute__ ((aligned (8))); }; This is an alternative to creating a union with a `double' member that forces the union to be double-word aligned. ----------------------------------------------------------------------- [4] Case Range ----------------------------------------------------------------------- Use case LOW ... HIGH: This has the same effect as the proper number of individual `case' labels, one for each integer value from LOW to HIGH, inclusive. This feature is especially useful for ranges of ASCII character codes: case 'A' ... 'Z': Write spaces around the `...'. ----------------------------------------------------------------------- [5] ElectricFence ----------------------------------------------------------------------- Add -lefence to detect memory overrun.