Attributes
V has several attributes that modify the behavior of functions and structs.
An attribute is specified inside []
right before a function/struct declaration and applies only to the following declaration.
// Calling this function will result in a deprecation warning
[deprecated]
fn old_function() {
}
// This function's calls will be inlined.
[inline]
fn inlined_function() {
}
// The following struct can only be used as a reference (`&Window`) and allocated on the heap.
[ref_only]
struct Window {
}
// V will not generate this function and all its calls if the provided flag is false.
// To use a flag, use `v -d flag`
[if debug]
fn foo() {
}
fn bar() {
foo() // will not be called if `-d debug` is not passed
}
// For C interop only, tells V that the following struct is defined with `typedef struct` in C
[typedef]
struct C.Foo {
}
// Used in Win32 API code when you need to pass callback function
[windows_stdcall]
fn C.DefWindowProc(hwnd int, msg int, lparam int, wparam int)