[CSUSB] >> [CompSci] >> [Dick Botting] >> [CS202 Course Materials] >> typedef
[Index] || [Contents] Tue Sep 10 16:33:59 PDT 2002


    The Type Definition Declaration.

    You know that you can declare classes, constants, variables, pointer variables,and arrays like this:
     		class Name { memeber_of_class };
     		const Type Name = Value;
     		      Type Name;
     		      Type *Name;
     		      Type Name[Constant];

    Sometimes we want to attach a name to a type of data. The syntax allows many forms:

     		typedef Type Name;
     		typedef Type *Name;
     		typedef Type Name[Constant];

    Syntactically a typedef statement is a variable declaration prefixed with the word "typedef" - no spaces, all lowercase!

  1. typedef_statement::= typedef variable_declaration.

    Semantically they do not create a variable. No storage is allocated. The declare a short name for what would be a long description of a type:

     		typedef stack<char> charstack;
     		typedef queue<Customer> Line;
     		typedef list<Student> Roster;
    		typedef vector<double> RowVector;
     		typedef double Vector [250];

    The name in the typedef can only be used to declare variables and constants.... and also to define other types using typedef.

    The usual advice holds:

    1. Make the name of the new type mean something.

Formulae and Definitions in Alphabetical Order