Linguagem de Programação Crystal

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 peformance 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.