The same plain-backtick "See sample: \`x.good.al\`." form fixed on al-methods-limited-during-write-transactions (PR #161) turned up repo-wide on 15 more of this PR's articles - Knowledge-Retrieval.ps1 requires the markdown-link form to associate a sample with its article. All 16 fixed; the four local validators (frontmatter, knowledge-index, knowledge-retrieval, review-fixtures, skill-index) pass.
1.5 KiB
| bc-version | domain | keywords | technologies | countries | application-area | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
style |
|
|
|
|
A var parameter must be called with a variable, never a literal or expression
Contributions welcome — open a PR to refine or extend this article.
Description
When a procedure declares a parameter with var, that parameter is passed by reference: the callee writes back into the caller's own memory location. This means the argument at the call site must be an actual variable, something with an address. A string literal, a numeric constant, or a computed expression has no address to write back to, so passing one to a var parameter fails to compile. Before writing a call, check the callee's signature for var on each parameter position being supplied a literal or expression — if present, a variable declared in the caller's own scope must be used instead.
Best Practice
Declare a variable in the caller's scope and pass it to the var parameter.
See sample: var-parameters-require-an-addressable-variable.good.al.
Anti Pattern
Passing a literal or a computed expression to a var parameter position fails to compile, because neither has an address the callee can write back to.
See sample: var-parameters-require-an-addressable-variable.bad.al.