Modeling C-Strings with MemoryLayout?

Jorn Vernee jorn.vernee at oracle.com
Mon Jan 2 11:21:22 UTC 2023


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