Modify for a variation of C with "size of" problem


I recently try to modify clang for a variation of C. The main difference between

the variation and the original one is that I wish to view the “size of” as a

function. Would anybody suggest me how to start doing??



Before anyone can help you, I think that you need to explain what you are trying to do a bit more clearly. In C, sizeof is not implemented as a function because it is impossible to implement it as a function. Consider two typical uses:


In the first case, it can't be a function because int is not a variable or constant and so can't be passed to a function. In the second case, it could be a function call, but the function would not know the type of a and so would not be able to return something useful.

So, when you say that you want sizeof to be viewed as a function, what do you actually mean?


-- Sent from my PDP-11

Because I want to support EFI C in clang. The main difference between ANSI C and EFI C(used in EFI Byte Code Virtual Machine)

is that int size is determined at running time (4-byte on 32-bit processor and 8-byte on 64-bit processor).

2010/12/15 David Chisnall <>

This does not require sizeof to be a function (in fact, as I said in my previous mail, sizeof can't be implemented as a function). It merely requires the result of sizeof not to be a constant expression. This is the case with variable-length arrays in C99 already. You could look at how these are implemented for an example.

Note, however, that if the size of int is not constant, you will probably not be able to use clang's codegen library (which generates LLVM IR) without some serious and invasive modifications, because it assumes that int is a fixed size in a lot of places and lowers it to i16, i32, or i64 in LLVM IR.


-- Sent from my Cray X1