]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/structs/structs-docs.factor
Fix permission bits
[factor.git] / basis / alien / structs / structs-docs.factor
1 USING: accessors alien.c-types strings help.markup help.syntax
2 alien.syntax sequences io arrays kernel words assocs namespaces
3 accessors ;
4 IN: alien.structs
5
6 ARTICLE: "c-structs" "C structure types"
7 "A " { $snippet "struct" } " in C is essentially a block of memory with the value of each structure field stored at a fixed offset from the start of the block. The C library interface provides some utilities to define words which read and write structure fields given a base address."
8 { $subsection POSTPONE: C-STRUCT: }
9 "Great care must be taken when working with C structures since no type or bounds checking is possible."
10 $nl
11 "An example:"
12 { $code
13     "C-STRUCT: XVisualInfo"
14     "    { \"Visual*\" \"visual\" }"
15     "    { \"VisualID\" \"visualid\" }"
16     "    { \"int\" \"screen\" }"
17     "    { \"uint\" \"depth\" }"
18     "    { \"int\" \"class\" }"
19     "    { \"ulong\" \"red_mask\" }"
20     "    { \"ulong\" \"green_mask\" }"
21     "    { \"ulong\" \"blue_mask\" }"
22     "    { \"int\" \"colormap_size\" }"
23     "    { \"int\" \"bits_per_rgb\" } ;"
24 }
25 "C structure objects can be allocated by calling " { $link <c-object> } " or " { $link malloc-object } "."
26 $nl
27 "Arrays of C structures can be created by calling " { $link <c-array> } " or " { $link malloc-array } ". Elements can be read and written using words named " { $snippet { $emphasis "type" } "-nth" } " and " { $snippet "set-" { $emphasis "type" } "-nth" } "; these words are automatically generated by " { $link POSTPONE: C-STRUCT: } "." ;
28
29 ARTICLE: "c-unions" "C unions"
30 "A " { $snippet "union" } " in C defines a type large enough to hold its largest member. This is usually used to allocate a block of memory which can hold one of several types of values."
31 { $subsection POSTPONE: C-UNION: }
32 "C union objects can be allocated by calling " { $link <c-object> } " or " { $link malloc-object } "."
33 $nl
34 "Arrays of C unions can be created by calling " { $link <c-array> } " or " { $link malloc-array } ". Elements can be read and written using words named " { $snippet { $emphasis "type" } "-nth" } " and " { $snippet "set-" { $emphasis "type" } "-nth" } "; these words are automatically generated by " { $link POSTPONE: C-UNION: } "." ;