Modeling C-Strings with MemoryLayout?

Jorn Vernee jorn.vernee at oracle.com
Mon Jan 2 11:31:15 UTC 2023


Sorry for the stale reply. My mail client wasn't pulling in emails it 
seems, so I didn't see the rest of the thread until just now.

On 02/01/2023 12:21, Jorn Vernee wrote:
> I'm not sure there is a good, generic answer to this question. What 
> kind of use case did you have in mind?
>
> The C string type `(const) char*` can be represented using C_POINTER. 
> The character array it points to could indeed be modeled using a 
> sequence layout. Though, I suppose the tricky bit is that C strings 
> are polymorphic. i.e. they can point to different data types 
> (character arrays with different lengths).
>
> Jorn
>
> On 25/12/2022 20:24, Gavin Ray wrote:
>> Is it possible to model C-Strings with MemoryLayouts?
>>
>> I was thinking of using "MemoryLayout.sequenceLayout(0, C_CHAR)" and 
>> computing the
>> length at runtime, plus manually adding the null-terminator.
>>
>> Would this work alright, or is there some better way to do this?


More information about the panama-dev mailing list