Next: Type casting
Up: Advanced use of gp2c
Previous: Type declaration
Under GP, all GP variables start with a default value, which is 0 for local
variables and 'v for gloval variable.
The gp2ccompiler follow this rule for variables declared without a type.
However, when a variable is declared with a type, gp2cwill not generate a
default value are generated. This means that local(g) is equivalent to
local(g:gen=0), but not to local(g:gen), and f(g)=... is
equivalent to f(g:gen=0)=..., but not to f(g:gen)=....
This rule was decided for several reasons:
- The value 0 might not be an object suitable for the type in question.
For example, local(v:vec) declare v as being of type vec. It make no sense to initialize v to 0 since 0 is not a valid vec object.
- This allows to define GP functions with mandatory arguments.
This way, GP will issue an error if a mandatory argument is missing.
Without this rule, there is no way to tell apart 0 and a missing argument.
- This allows to tell gp2cto not generated useless default values.
Next: Type casting
Up: Advanced use of gp2c
Previous: Type declaration
Bill Allombert
2006-01-28