Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
D (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====Lifetime safety of assignments==== Within @safe code, the lifetime of an assignment involving a [[reference type]] is checked to ensure that the lifetime of the assignee is longer than that of the assigned. For example: <syntaxhighlight lang="D"> @safe void test() { int tmp = 0; // #1 int* rad; // #2 rad = &tmp; // If the order of the declarations of #1 and #2 is reversed, this fails. { int bad = 45; // The lifetime of "bad" only extends to the scope in which it is defined. *rad = bad; // This is valid. rad = &bad; // The lifetime of rad is longer than bad, hence this is not valid. } } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)