[OT] OT: Null checks.

Walter Bright newshound2 at digitalmars.com
Sun May 4 01:36:57 UTC 2025


On 5/3/2025 6:19 PM, Walter Bright wrote:
> ```
> int main()
> {
>      int* p = (int*)0;
>      int& q = *p;
>      return q;
> }
> ```
> ```
> g++ x.c
> ./a.out
> Segmentation fault (core dumped)
> ```


The D version with the small DMD compiler:

```
int main()
{
     int* p = null;
     ref int q = *p;
     return q;
}
```
```
dmd x.d -O
x.d(6): Error: null dereference in function _Dmain
```


More information about the Digitalmars-d mailing list