2 USING: io io.encodings.ascii io.files io.files.temp io.launcher
3 locals math.parser sequences sequences.deep
9 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
15 Values: HEADERS sequence TYPE string n integer ..
19 Use 'size-of' to find out the size in bytes of a C type.
21 The 'headers' argument is a list of header files to use. You may
22 pass 'f' to only use 'stdio.h'. ..
26 ! Find the size of 'int'
32 ! Find the size of the 'XAnyEvent' struct from Xlib.h
34 { "X11/Xlib.h" } "XAnyEvent" size-of . ..
38 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
40 :: size-of ( HEADERS TYPE -- n )
42 [let | C-FILE [ "size-of.c" temp-file ]
43 EXE-FILE [ "size-of" temp-file ]
44 INCLUDES [ HEADERS [| FILE | { "#include <" FILE ">" } concat ] map ] |
49 "main() { printf( \"%i\" , sizeof( " TYPE " ) ) ; }"
52 flatten C-FILE ascii set-file-lines
54 { "gcc" C-FILE "-o" EXE-FILE } try-process
56 EXE-FILE ascii <process-reader> contents string>number ] ;
58 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!