<div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Note: C does not support this.  GCC has an extension (variable length 
arrays in structs), but clang doesn’t support it and it’s a terrible 
idea.</blockquote><div>It might be complex but it is not terrible. Depends on the language capabilities implementing it. Delphi for example allows exactly that and finalizes its records through RTTI which allows to automatically free up the memory. <br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-07-14 10:26 GMT+02:00 David Chisnall via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 14 Jul 2017, at 09:12, Christer Swahn via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> I'm looking into ways to represent complex aggregate types whose members and/or sub-members may be dynamically sized. This would conceptually correspond to a C struct containing other structs and arrays, and some of those arrays would have a length that is not known in compile time.<br>
<br>
</span>Note: C does not support this.  GCC has an extension (variable length arrays in structs), but clang doesn’t support it and it’s a terrible idea.<br>
<span class=""><br>
> LLVM IR allows me to do this for a top-level array (using 0 as its LLVM data type length and manually computing its needed allocation size).<br>
><br>
> As far as I understand, if I want to represent structs containing dynamic arrays containing structs and so on, I will have to roll my own data size computation, element pointer computation and so on. This however seems to be a significant risk to portability and alignment handling.<br>
><br>
> Does anyone here have any experience with similar use cases, or any advice on how to handle this?<br>
<br>
</span>You will have to do this manually, via pointer casts of the results of GEPs.<br>
<br>
David<br>
<br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br></div>