next up previous contents index
Next: Functions Up: More About C++ Previous: More About C++   Contents   Index

Names and Types

Names of variables and functions may consist (only) of letters, digits, and the underscore character. The first character of a name must not be a digit, and the language standard reserves names starting with underscore for library authors. Names are case-sensitive, but it's usually a bad idea to use a single name capitalized and uncapitalized in a single file. Numerous capitalization conventions are used informally; this document uses uncapitalized words separated by underscores for variables and functions, and occasionally uses all capitals for constants. As with names of LATEX macros, primary considerations are clarity (of meaning), readability, and consistency.

Every variable in C++ has a ``type'', such as integer (int), double-precision floating point (double), or Boolean (bool, true or false). ePiX provides additional types, the most common of which is P, for point. The construct P(x,y,z) creates $ (x,y,z)$, while P(x,y) gives $ (x,y,0)$, which is effectively the pair $ (x,y)$. A variable is defined by giving its type, its name, and an initializing expression.

In C and C++, a pointer is a variable that holds the memory address of another variable. Though more subtle than ordinary variables, pointers are useful in expressing certain algorithms, such as sorting. In Japan, buildings' addresses are assigned chronologically, rather than according to street location. A building is analogous to a variable, while the address is a pointer. If the Japanese parliament passed a law mandating that buildings be addressed consecutively along the street, there would be two ways to proceed: Dig up and relocate each physical building (move variables), or re-number the buildings in place (sort pointers). For similar reasons of efficiency, C++'s sorting algorithms work with pointers.

C++ also provides reference variables, which allow a variable to be given an additional name. Their use arises because of the way C++ functions treat their arguments.


next up previous contents index
Next: Functions Up: More About C++ Previous: More About C++   Contents   Index
Andrew D. Hwang 2004-09-04