On Thursday, 5 January 2023 at 09:10:00 UTC, areYouSureAboutThat wrote:
My question is: why is there no bounds checking occurring if I forget to use -betterC?

module test;

extern(C) void main()

Note that whether bounds checking is performed depends on [compiler switches](https://dlang.org/dmd-windows.html#switch-boundscheck), and that there is a mode where `@safe` functions are checked, but `@system` functions (which your `main` appears to be) are not. This mode is the default for `-release` builds:
```
-boundscheck=[on|safeonly|off ]
Controls if bounds checking is enabled.
on: Bounds checks are enabled for all code. This is the default.

safeonly: Bounds checks are enabled only in @safe code. This is the default for -release builds.

off: Bounds checks are disabled completely (even in @safe code). This option should be used with caution and as a last resort to improve performance. Confirm turning off @safe bounds checks is worthwhile by benchmarking.
```
So, if you want bounds checking, make sure you either have `-boundscheck=on`, or use an `@safe` function together with `-boundscheck=safeonly`.
  • forgetting -bett... areYouSureAboutThat via Digitalmars-d-learn
    • Re: forgett... areYouSureAboutThat via Digitalmars-d-learn
      • Re: for... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: for... Mathias LANG via Digitalmars-d-learn
    • Re: forgett... Tejas via Digitalmars-d-learn
    • Re: forgett... tsbockman via Digitalmars-d-learn

Reply via email to