<div dir="ltr"><div>Hi Marcel,</div><div><br></div>Do you think that the dimensions are always known? I understood that you also need to know the cardinality 

per dimension

of the involved arrays. If you want to remember only the number of dimensions, some of my remarks may not apply. Note that an int** is not a two-dimensional array int[x][y], so it might be misleading to speak of dimensions. From practice I know we would need to support at least three pointer indirections, not only two, at least if you don't want to require intermediate type aliases for pointers in some cases. See below.<div><br></div><div>Look at the CredRead function and CREDENTIALS struct for example:</div><div><a href="https://docs.microsoft.com/en-us/windows/win32/api/wincred/nf-wincred-credreadw">https://docs.microsoft.com/en-us/windows/win32/api/wincred/nf-wincred-credreadw</a></div><div><a href="https://docs.microsoft.com/de-de/windows/win32/api/wincred/ns-wincred-credentialw">https://docs.microsoft.com/de-de/windows/win32/api/wincred/ns-wincred-credentialw</a></div><div><br></div><div>The CredRead function takes essentially a CREDENTIAL** as an output parameter, so it will give you (dereferencing the passed argument) one CREDENTIAL*. It is like passing a PCREDENTIAL[1] variable, but you could well pass it a PCREDENTIAL[6] if you like, since both decay to PCREDENTIAL* when passed as arguments. Anyway, this is not a two-dimensional array of CREDENTIALs.</div><div><br></div><div>For more fun, consider CredEnum: <a href="https://docs.microsoft.com/en-us/windows/win32/api/wincred/nf-wincred-credenumeratew">https://docs.microsoft.com/en-us/windows/win32/api/wincred/nf-wincred-credenumeratew</a></div><div>It takes a CREDENTIAL***

 to give you back an array of pointers to CREDENTIAL structs. How many there are, you will only learn by dereferencing the count argument. The actual CREDENTIAL structures /could/ be laid out as a CREDENTIAL[count] array, but they don't need to be (implementation detail). So there is a one-dimensional array of pointers, there could be, but needn't be, a one-dimensional array of CREDENTIALs, but certainly there are no two- or three-dimensional arrays here.</div><div><br></div><div>Kind regards,<br>Jakob</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am So., 14. Juni 2020 um 18:19 Uhr schrieb Marcel Taeumel <<a href="mailto:marcel.taeumel@hpi.de">marcel.taeumel@hpi.de</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div id="gmail-m_4727447114438230089__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0)">Hi all!<div></div><div><br></div><div>For some days now, I am thinking about "pointer-to-pointer" types. I suppose that the more general topic is the interpretation of multi-dimensional arrays.</div><div><br></div><div>On the one hand, this is an in-image issue to correctly read ExternalData and to generate appropriate accessors for struct fields.</div><div><br></div><div>On the other hand, this may affect FFI call's arg coercing and return-type packaging.</div><div><br></div><div>So, after playing around with an implementation of pointer-to-pointer types via ExternalType's #referencedType (i.e. making it a chain of three: ... -> void -> void* -> void** -> void ...), I figured that we might need to store the array dimensions in the compiledSpec.</div><div><br></div><div>Here are some unused bits for that:</div><div><img id="gmail-m_47274471144382300899bbaa22c-4c0c-4bdb-83ea-459b9ebee086" src="cid:172b3f6823bcb971f161" width="auto"><br></div><div><div><span style="white-space:pre-wrap">    </span>FFIFlagPointerArrayMask := 16rF00000. "up to 16-dimensional arrays"</div><div><span style="white-space:pre-wrap">    </span>FFIFlagPointerArrayShift := 20.</div></div><div><br></div><div>Here are some questions for you on this topic:</div><div><br></div><div>- Should we reserve all 4 bits? 16-dimensional arrays sound like overkill ... 2 bits could be enough, having rarely the lower one set for char** ...</div><div>- In the image, would you store all possible versions through refrencedType in a linked cycle? Or would you lazily create them ... on the fly? As requested from struct fields and FFI call specs via ExternalType class >> #typeNamed: ?</div><div>- In the FFI plugin, do you see value in coercing an array of, for example, IntegerArrays for an FFI call? (int**)</div><div>- In the FFI plugin, do you see value in automatically packaging returned objects if those dimensions would be zero-terminated?</div><div><br></div><div>Best,</div><div>Marcel</div></div><br>
</blockquote></div>