News for hackers. Stuff that matters.
Re:How can I get this 8 year old VBA 64-bit compiler bug fixed? by sk5t on Sunday August 15, 2021 @12:16PM (#28189957)
(Tangential) Got to scratch my head at this "authoritatively voiced" bit of advice in the SO thread:

> Testing the result of a constructor in any language is probably a dodgy practice. It's an object or it's a 'null'.

Ah, if there's an OO language anywhere that can return null from a constructor invocation, I have yet to see it.

Re:How can I get this 8 year old VBA 64-bit compiler bug fixed? by benibela on Sunday August 15, 2021 @04:29PM (#28192232)
Delphi/Pascal has 2-layered constructors.

There is a virtual class method to allocate memory and a so called constructor that initializes fields that should be zero.

The user of a class, only calls the constructor. The constructor then calls the memory-allocation method implicitly (you can see the call with a disassembler, but not in the Pascal code).

Anyways, you can override the memory-allocation method for each class. E.g. a useful case would be to build an arena allocator just for that class. But you can also override it, so that calling the class constructor returns a null

Re:How can I get this 8 year old VBA 64-bit compiler bug fixed? by kevingadd on Sunday August 15, 2021 @02:27PM (#28191094)
C# constructors technically don't return anything (afaik), the object is allocated and then the constructor is invoked on it. So it's theoretically possible for your compiled code to produce a null as the result of a 'new' expression. I think this wouldn't be spec compliant though, since the two scenarios where this would make sense (OOM and exception thrown during alloc or ctor) should just throw and unwind before you can see observe the null or uninitialized instance.

FWIW, it's also possible to enter an instance method with a null 'this' under certain circumstances (normally there would be a null reference check before entering the method body, but I've run into cases where there wasn't)

Contrived scenario: You AOT-compile your code in a 'no exceptions' mode, so the generated code assumes that malloc can't throw, etc. In that case if a failure happens during the 'new' process the only reasonable return values are either null or an instance with garbage data in it. As a compiler author, out of the two I'd probably pick null. This isn't as far-fetched as it sounds since right now exception handling in WebAssembly is a nightmare.

Actually, I wonder if an exception filter could observe the null before the unwind happens...

Re:How can I get this 8 year old VBA 64-bit compiler bug fixed? by pwdisswordfish8 on Sunday August 15, 2021 @01:45PM (#28190688)
C++ with new(std::nothrow)?
Re:How can I get this 8 year old VBA 64-bit compiler bug fixed? by rzzzt on Sunday August 15, 2021 @03:04PM (#28191458)
Or maybe if a new_handler is installed, which returns.
Re:How can I get this 8 year old VBA 64-bit compiler bug fixed? by TillE on Sunday August 15, 2021 @10:25PM (#28194400)
operator new can return null, certainly, but that's the memory allocator and not the constructor.
Re:How can I get this 8 year old VBA 64-bit compiler bug fixed? by thom on Sunday August 15, 2021 @12:33PM (#28190128)
Dunno if this counts but it’s not unheard of to return nil from init methods in Objective-C.
Re:How can I get this 8 year old VBA 64-bit compiler bug fixed? by hugey010 on Sunday August 15, 2021 @01:24PM (#28190524)
Yep, afaik if allocation of memory for the object fails it's canonical to immediately return nil.