Why ArrayDim is always 2?

#define CPP_ARRAY_DIM(ArrayName, ClassName)
(sizeof(((ClassName*)0)->ArrayName) / sizeof(((ClassName*)0)->ArrayName[0]))

I see how unreal calculate the len of an array.But why the result is always 2? I use it during UHT running.please help,thank you.

Hi,

UHT uses a UProperty::ArrayDim state of ‘2’ during parsing to mean ‘this property is a C array’ (and ‘1’ to mean ‘TArray’ and ‘0’ to mean ‘not an array’). It does not hold the actual array dimension because UHT is not an intelligent enough C++ parser to work it out in all cases.

During code generation, ‘2’ is then translated into a CPP_ARRAY_DIM() at code generation, and then the C++ compiler works out the correct value for us, as it can harness the full power of C++ parsing.

Really, this variable should be an enum. It was originally migrated from code which did attempt to parse the array dimensions, but it failed for C arrays that had anything other than a literal dimension or an enumerator in a UEnum.

Hope this aids your understanding,

Steve