Search⌘ K

Code Safety Attributes

Explore code safety attributes in D programming including @safe, @trusted, and @system. Understand how these attributes ensure memory safety by restricting unsafe operations, how trusted code communicates safety despite bypassing some restrictions, and how system functions represent default safety levels. Gain the ability to write safer code and manage function safety properly.

@safe, @trusted, and @system are about the code safety that a function provides. As with purity, the compiler infers the safety level of templates, delegates, anonymous functions, and auto functions.

@safe functions

A class of programming errors involves corrupting data at unrelated locations in memory by writing at those locations unintentionally. Such errors are mostly due to mistakes made in using pointers and applying type casts.

@safe functions ...