W3cubDocs

/Crystal 0.31

Uninitialized variable declaration

Crystal allows declaring uninitialized variables:

x = uninitialized Int32
x #=> some random value, garbage, unreliable

This is unsafe code and is almost always used in low-level code for declaring uninitialized StaticArray buffers without a performance penalty:

buffer = uninitialized UInt8[256]

The buffer is allocated on the stack, avoiding a heap allocation.

The type after the uninitialized keyword follows the type grammar.

To the extent possible under law, the persons who contributed to this workhave waived
all copyright and related or neighboring rights to this workby associating CC0 with it.
https://crystal-lang.org/docs/syntax_and_semantics/declare_var.html