A statement found in a function body always has specific requirements as to what
type the final expression must be:
-
Evaluation Statement: Cannot be non-simple type. A void
type is permitted (results from a function call with no return
value or structure-to-structure assignment).
-
The “return” statement: If a function has a return value, it
cannot be a structure type. A scalar result
is automatically cast to a scalar return type and a pointer
result is automatically cast to a pointer return type.
It is not possible to cast pointer types to scalar types or vice versa (with
0 being an exception for pointer return types—this represents a
null pointer).
-
The “if,” “while,” and “do” statements: Cannot be a structure
type. A void type is not permitted.
Either scalar or pointer types
are allowed.
-
The “for” statement: None of the expressions can result in a
structure type. A void type is permitted
for the initialization expression and increment
expression, but not for the evaluation expression.
Either scalar or pointer types
are allowed for all expressions.
-
The “switch” statement: Cannot be a non-simple type.
Only certain scalar integer types are permitted, including
char, short, and long.
Automatic typecasting is never performed on the final result.
-
Function arguments: If a function parameter type is scalar,
the argument must also be scalar; the argument is
automatically cast to the parameter type. If a function parameter type is
pointer, the argument must also be a pointer to the same type
if the parameter type is not pointer-to-void, or a pointer to
any type if the parameter type is pointer-to-void.
See also: [Final expression
type result] [L-value status gain and loss]
[Overly complex expressions] [Limitations
on pointer usage] [Structure member
dereference: bit scan blocks]
|