[cfe-dev] Number of elements in ArrayType?

Kenth Eriksson via cfe-dev cfe-dev at lists.llvm.org
Tue Oct 29 11:20:52 PDT 2019


On Tue, 2019-10-29 at 15:03 +0100, Csaba Dabis wrote:
> 
> Assume that you have the desired `VarDecl` `D`:
> ```
>        const Expr *SizeExpr = nullptr;
>         if (D->getType()->isArrayType())
>           if (const TypeSourceInfo *TSI = D->getTypeSourceInfo())
>             if (const auto ATL = TSI->getTypeLoc().getAs<ArrayTypeLoc>())
>               SizeExpr = ATL.getSizeExpr();
> ```
> 
Looks as it can be done like this (arr is ConstantArrayType)

arr->getSize().getZExtValue()

Is my understanding correct?



More information about the cfe-dev mailing list