Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
invalid memory access from uninitialized variable #4544
I'm not sure if this is a bug but it's definitely unexpected behavior
uninitialized variables should not pass
exactly the opposite
compile that then run it
So, I can test if it's nil and it tells me it's not. I can test if it exists and it tells me it does, but if i try and do anything with it, it blows up.
In my code i had to change it to
When you use it, you basically renounce most of the safety guarantees that Crystal provides, for the sake of performance or interoperability with C code.
Are you sure you really need to use declare an uninitialized var? What would be your use case?
You can always model what you would have done with uninitialized with nil, and it'll be safer and cleaner code. The only use for
Unless you're binding C code then
For reference, there's no way to know if a variable is initialized or not because it will contain entirely random data. If it's a reference it will likely point to uninitialized memory (at least on 64bit), if it's a struct it will contain garbled data. There's no sane way to detect what is uninitialized.