float init 0 request
pete
email at email.com
Sun Aug 16 08:32:13 UTC 2026
On Sunday, 16 August 2026 at 02:00:29 UTC, Walter Bright wrote:
> On 8/15/2026 3:13 AM, pete wrote:
>> typedef struct VkClearDepthStencilValue {
>> float depth = 0;
>> uint32_t stencil;
>> } VkClearDepthStencilValue;
>
> will default initialize .depth to 0.0. May I suggest doing a
> grep across your C++ derived declarations looking for floats
> and doubles.
I usually do this now but I occasionally forget and it would not
be obvious to someone who hadn't already been bitten by the
problem in the first place.
Most people would assume the default would just be zero and if
you are going to violate the principle of least surprise by
making it different then the result of using the nan should be
immediate and obvious. If it worked like a null pointer
dereference then it would make sense because they are easy to
track down. The default nan is just the compiler working behind
your back inserting poison. Then when you run it things just
"don't work right" in non obvious ways and you either (1) leave
it thinking you're just having a bad day at the keyboard or (2)
debug the whole thing to see where the data deviates from what
you expected and (2a) curse loudly when you realise what the
compiler just did to you :)
More information about the Digitalmars-d
mailing list