Skip to content

Latest commit

 

History

History
19 lines (12 loc) · 589 Bytes

declare_var.md

File metadata and controls

19 lines (12 loc) · 589 Bytes

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.