Some types and methods can be annotated with attributes. The attribute list is fixed, but eventually (maybe) there will be user-defined attributes.
Tells the compiler how to link a C library. This is explained in the lib section.
Marking a Crystal struct with this attribute makes it possible to use it in lib declarations:
struct MyStruct end lib MyLib fun my_func(s : MyStruct) # OK (gives an error without the Extern attribute) end
You can also make a struct behave like a C union (this can be pretty unsafe):
# A struct to easily convert between Int32 codepoints and Chars
@[ThreadLocal] attribute can be applied to class variables and C external variables. It makes them be thread local.
class DontUseThis # One for each thread @@values =  of Int32 end
ThreadLocal is used in the standard library to implement the runtime and shouldn't be needed or used outside it.
Marks a C struct as packed, which prevents the automatic insertion of padding bytes between fields. This is typically only needed if the C library explicitly uses packed structs.
Gives a hint to the compiler to always inline a method:
def foo 1 end
Tells the compiler to never inline a method call. This has no effect if the method yields, since functions which yield are always inlined.
def foo 1 end
Marks a method or lib fun as returning twice. The C
setjmp is an example of such a function.
Indicates the call convention of a lib fun. For example:
lib LibFoo fun foo : Int32 end
The list of valid call conventions is:
- C (the default)
They are explained here.
Marks an enum as a "flags enum", which changes the behaviour of some of its methods, like