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.

  1. // Calling this function will result in a deprecation warning
  2. [deprecated]
  3. fn old_function() {
  4. }
  5. // This function's calls will be inlined.
  6. [inline]
  7. fn inlined_function() {
  8. }
  9. // The following struct can only be used as a reference (`&Window`) and allocated on the heap.
  10. [ref_only]
  11. struct Window {
  12. }
  13. // V will not generate this function and all its calls if the provided flag is false.
  14. // To use a flag, use `v -d flag`
  15. [if debug]
  16. fn foo() {
  17. }
  18. fn bar() {
  19. foo() // will not be called if `-d debug` is not passed
  20. }
  21. // For C interop only, tells V that the following struct is defined with `typedef struct` in C
  22. [typedef]
  23. struct C.Foo {
  24. }
  25. // Used in Win32 API code when you need to pass callback function
  26. [windows_stdcall]
  27. fn C.DefWindowProc(hwnd int, msg int, lparam int, wparam int)

Appendices