Is there any way to specify that a variable, member or parameter can't be null?
Thread overview | ||||||
---|---|---|---|---|---|---|
|
June 20, 2022 Enforce not null at compile time? | ||||
---|---|---|---|---|
| ||||
June 20, 2022 Re: Enforce not null at compile time? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Antonio | On Monday, 20 June 2022 at 17:48:48 UTC, Antonio wrote: >Is there any way to specify that a variable, member or parameter can't be null? Depends on the type. Basic types can't be null. Pointers and classes can always be |
June 20, 2022 Re: Enforce not null at compile time? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Antonio | On Monday, 20 June 2022 at 17:48:48 UTC, Antonio wrote: >Is there any way to specify that a variable, member or parameter can't be null? You can use an invariant if it's a member of an aggregate but be warned that these are only checked at the boundaries of public member functions. |
June 20, 2022 Re: Enforce not null at compile time? | ||||
---|---|---|---|---|
| ||||
Posted in reply to max haughton | On Monday, 20 June 2022 at 19:08:32 UTC, max haughton wrote: >On Monday, 20 June 2022 at 17:48:48 UTC, Antonio wrote: >Is there any way to specify that a variable, member or parameter can't be null? You can use an invariant if it's a member of an aggregate but be warned that these are only checked at the boundaries of public member functions. I'm using preconditions when calling functions
But it's runtime validation, not formally validated by compiler. |