Returns the size of the given type. You may optionally specify
additional headers to search in for the type.
If found, a macro is passed as a preprocessor constant to the compiler
using the type name, in uppercase,
prepended with ‘SIZEOF_’, followed by the type name, followed by ‘=X’ where ‘X’
is the actual size.
For example, if check_sizeof(‘mystruct’) returned
12, then the SIZEOF_MYSTRUCT=12 preprocessor macro would be passed to the
compiler.
# File lib/mkmf.rb, line 1007
def check_sizeof(type, headers = nil, opts = "", &b)
typename, member = type.split('.', 2)
prelude = cpp_include(headers).split(/$/)
prelude << "typedef #{typename} rbcv_typedef_;\n"
prelude << "static rbcv_typedef_ *rbcv_ptr_;\n"
prelude = [prelude]
expr = "sizeof((*rbcv_ptr_)#{"." << member if member})"
fmt = STRING_OR_FAILED_FORMAT
checking_for checking_message("size of #{type}", headers), fmt do
if UNIVERSAL_INTS.include?(type)
type
elsif size = UNIVERSAL_INTS.find {|t|
try_static_assert("#{expr} == sizeof(#{t})", prelude, opts, &b)
}
$defs.push(format("-DSIZEOF_%s=SIZEOF_%s", type.tr_cpp, size.tr_cpp))
size
elsif size = try_constant(expr, prelude, opts, &b)
$defs.push(format("-DSIZEOF_%s=%s", type.tr_cpp, size))
size
end
end
end