passing_20substructures_20to_20procedures
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| passing_20substructures_20to_20procedures [2018/03/31 13:19] – external edit 127.0.0.1 | passing_20substructures_20to_20procedures [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| //by Richard Russell, August 2006//\\ \\ As described in the [[http:// | //by Richard Russell, August 2006//\\ \\ As described in the [[http:// | ||
| + | <code bb4w> | ||
| DIM object{name$, | DIM object{name$, | ||
| object.pos.x = 1.0 | object.pos.x = 1.0 | ||
| Line 11: | Line 12: | ||
| DEF FN_distance(s{}) | DEF FN_distance(s{}) | ||
| = SQR(s.pos.x^2 + s.pos.y^2 + s.pos.z^2) | = SQR(s.pos.x^2 + s.pos.y^2 + s.pos.z^2) | ||
| + | </ | ||
| However you //cannot// pass an entire **substructure** to a procedure or function. The following code doesn' | However you //cannot// pass an entire **substructure** to a procedure or function. The following code doesn' | ||
| + | <code bb4w> | ||
| REM This doesn' | REM This doesn' | ||
| DIM object{name$, | DIM object{name$, | ||
| Line 22: | Line 25: | ||
| DEF FN_distance(p{}) | DEF FN_distance(p{}) | ||
| = SQR(p.x^2 + p.y^2 + p.z^2) | = SQR(p.x^2 + p.y^2 + p.z^2) | ||
| + | </ | ||
| In most cases passing the parent structure instead, as in the first example, isn't a major inconvenience, | In most cases passing the parent structure instead, as in the first example, isn't a major inconvenience, | ||
| + | <code bb4w> | ||
| DIM object{name$, | DIM object{name$, | ||
| object.pos.x = 1.0 | object.pos.x = 1.0 | ||
| Line 31: | Line 36: | ||
| DEF FN_distance(s{}, | DEF FN_distance(s{}, | ||
| - | | + | |
| = SQR(p.x^2 + p.y^2 + p.z^2) | = SQR(p.x^2 + p.y^2 + p.z^2) | ||
| + | </ | ||
| Note the manipulation of memory in **FN_distance** which makes this work.\\ \\ Now you //can// use the same function with a differently-named substructure: | Note the manipulation of memory in **FN_distance** which makes this work.\\ \\ Now you //can// use the same function with a differently-named substructure: | ||
| + | <code bb4w> | ||
| DIM newobj{type%, | DIM newobj{type%, | ||
| newobj.loc.x = 4.0 | newobj.loc.x = 4.0 | ||
| Line 40: | Line 47: | ||
| PRINT FN_distance(newobj{}, | PRINT FN_distance(newobj{}, | ||
| END | END | ||
| + | </ | ||
passing_20substructures_20to_20procedures.1522502372.txt.gz · Last modified: 2024/01/05 00:17 (external edit)