Align pragma

The align pragma is for variables and object field members. It modifies the alignment requirement of the entity being declared. The argument must be a constant power of 2. Valid non-zero alignments that are weaker than other align pragmas on the same declaration are ignored. Alignments that are weaker that the alignment requirement of the type are ignored.

  1. type
  2. sseType = object
  3. sseData {.align(16).}: array[4, float32]
  4. # every object will be aligned to 128-byte boundary
  5. Data = object
  6. x: char
  7. cacheline {.align(128).}: array[128, char] # over-aligned array of char,
  8. proc main() =
  9. echo "sizeof(Data) = ", sizeof(Data), " (1 byte + 127 bytes padding + 128-byte array)"
  10. # output: sizeof(Data) = 256 (1 byte + 127 bytes padding + 128-byte array)
  11. echo "alignment of sseType is ", alignof(sseType)
  12. # output: alignment of sseType is 16
  13. var d {.align(2048).}: Data # this instance of data is aligned even stricter
  14. main()

This pragma has no effect for the JS backend.