float init 0 request

Alexandru Ermicioi alexandru.ermicioi at gmail.com
Fri Aug 14 10:42:16 UTC 2026


On Friday, 14 August 2026 at 08:09:45 UTC, Jonathan M Davis wrote:
> The language relies on the ability to default-initialize 
> objects. For instance, that's what happens when you allocate a 
> dynamic array or increase its length. There has to be a default 
> value for that to work. It's part of why adding the ability to 
> disable default initialization for structs has been a mess. 
> It's arguably necessary for some contexts, but it means that 
> those structs can't legally be used in any context where 
> default initialization is required. Doing the same to floating 
> point types would be even worse given that they're a built-in 
> type rather than something specific to a particular code base.

Right, that would cause mayhem in templated code, an extra static 
if at minimum.

> Also, languages like Java where they make it illegal to use a 
> variable before you give it a value show how problematic it can 
> be to make it an error to not explicitly initialize a variable, 
> because it's pretty easy to get into situations where you know 
> for sure that the variable is given a value before it's used, 
> but the compiler isn't smart enough to figure that out, so 
> you're forced to give it a dummy value just to shut it up.

Nowadays java compiler seems smarter, it doesn't force you 
initialize it at declaration site, if all branches after 
declaration get var initialized before its use.




More information about the Digitalmars-d mailing list