[cfe-dev] portable sizeof

Jochen Wilhelmy j.wilhelmy at arcor.de
Fri Oct 30 10:47:58 PDT 2009


Hi!

while playing with clang I found that sizeof() is evaluated in the frontend,
e.g. generating llvm-code like

store i32 16, i32* %tmp1

(the size of the struct Foo is 16 byte).

would it be better to generate code like this?

store i32 ptrtoint (struct.Foo* getelementptr inbounds (%struct.Foo* null, i32 1) to i32), i32* %tmp1

this way c-code containing a sizeof could be compiled to llvm bytecode
while the target platfrom is still mostly unknown (at least size_t has 
to be known
and influences whether i16, i32 or i64 is used)

In my example Foo contains and int and a double. Therefore sizeof(Foo) 
also may be 12.

-Jochen




More information about the cfe-dev mailing list