Skip to content

Slices and printfs #37

Open
Open
@zhiayang

Description

@zhiayang

Currently the compiler automatically converts a str to its pointer when passing it to a C-style vararg function (eg. printf) (see

// auto-convert strings and char slices into char* when passing to va_args
)

Of course this kinda defeats the purpose, since slices are not necessarily null-terminated. The proposed alternative (which I'm proposing now) is to pass the entire struct to printf, which will cause it to get both the length and the pointer.

(aside: the layout of str is like this: struct str { len: i64; ptr: &i8 })

Then, we would need to call printf with %.*s instead of just %s.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions