digitalmars.D.learn - Implicit nothrow with -betterC
- Manuel Maier (17/22) Dec 03 2017 I've been experimenting with the -betterC switch and stumbled
- Adam D. Ruppe (12/15) Dec 03 2017 betterC doesn't change the language, it just doesn't compile in
- Manuel Maier (1/1) Dec 09 2017 Thanks Adam, that cleared it up for me.
I've been experimenting with the -betterC switch and stumbled
upon something that didn't quite make sense to me.
I've put together a small example [1] of Win32 code with a window
callback that has to be nothrow as per the definition of WNDPROC
somewhere in core.sys.windows. However, calling anything from
within the window callback not marked as nothrow will result in a
compile error. This behavior is expected for regular D code and
there are many ways to fix the code so the compiler no longer
emits the error. What bugs me is the following.
According to the docs, exceptions "won't work":
From https://dlang.org/spec/betterc.html#consequences
As no Druntime is available, many D features won't work. For
example:
[...]
7. Exceptions
[...]
To me, this means it should be impossible to write -betterC code
that throws exceptions. So shouldn't -betterC imply nothrow on
all functions by default? Is this a compiler bug? If not, in what
way is the explicit nothrow attribute still useful for -betterC?
[1]
https://gist.github.com/Manuzor/81cc01d57543202d68eab5a84d944027
Dec 03 2017
On Sunday, 3 December 2017 at 15:24:27 UTC, Manuel Maier wrote:I've been experimenting with the -betterC switch and stumbled upon something that didn't quite make sense to me.betterC doesn't change the language, it just doesn't compile in all the features automatically. So rules about nothrow etc. decorations are still in place, even if the feature isn't actually available at this time. The same code you build with -betterC can almost always be built without the switch too, and continue to work the same way.According to the docs, exceptions "won't work":That may be a temporary restriction. It is already possible to do exceptions with -betterC code if you link in the functions yourself (notably, betterC modules are permitted to be used in a regular druntime based application), and in the future, such may be done automatically on demand too.
Dec 03 2017








Manuel Maier <mjmaier gmx.de>