Contents|Index|Previous|Next
 Naming an expressions type  

You can give a name to the type of an expression using a typedef declaration with an initializer. The following example shows how to define name as a type name for the type of exp. This is useful in conjunction with the statements-within-expressions feature.

The following shows how the two together can be used to define a safe “maximum” macro that operates on any arithmetic type.

The reason for using names that start with underscores for the local variables is to avoid conflicts with variable names that occur within the expressions that are substituted for ‘a’ and ‘b’. Eventually we hope to design a new form of declaration syntax that allows you to declare variables whose scopes start only after their initializers; this will be a more reliable way to prevent such conflicts.