2 USING: io io.encodings.ascii io.files io.files.temp io.launcher
3 locals math.parser sequences sequences.deep ;
7 ! Use 'size-of' to find out the size in bytes of a C type.
9 ! The 'headers' argument is a list of header files to use. You may
10 ! pass 'f' to only use 'stdio.h'.
16 ! { "X11/Xlib.h" } "XAnyEvent" size-of .
18 :: size-of ( HEADERS TYPE -- n )
20 [let | C-FILE [ "size-of.c" temp-file ]
21 EXE-FILE [ "size-of" temp-file ]
22 INCLUDES [ HEADERS [| FILE | { "#include <" FILE ">" } concat ] map ] |
27 "main() { printf( \"%i\" , sizeof( " TYPE " ) ) ; }"
30 flatten C-FILE ascii set-file-lines
32 { "gcc" C-FILE "-o" EXE-FILE } try-process
34 EXE-FILE ascii <process-reader> contents string>number ] ;
36 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!