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