Skip to content

A str passed in a variadic C position is read as two words #2574

Closed

Description

@ehartford

Spec §16.3c / §16 (a const char * parameter accepts a str, passed as NUL-terminated input text). A variadic position has no parameter type, and the compiler passes the fat str value as is; C reads its pointer, then its length word as the next argument.

Repro (installed compiler, main 8fda443):

use std.libc
fprintf(libc_stderr(), c"%s|%d\n".ptr, "compress", 7)
fprintf(libc_stderr(), c"%s|%d\n".ptr, c"compress".ptr, 8)

Expected compress|7 then compress|8; actual compress|8 twice (the first %d read the str's length, 8).

Expected: a str in a variadic C position is lent as its NUL-terminated pointer, as a const char * parameter lends it, or the call is refused with a diagnostic naming the position. Workaround: c"...".ptr (the migrator renders a literal there so since #2556; the basic-tests fixture macro_body_string_literal now expects it).

Activity

  1. ehartford commented on Oct 23, 2026

    @ehartford
    ContributorAuthor

    Fixed in #2580 (c7fa606): a str (or &str) in a variadic slot is given the promoted type *const c_char (record_c_promoted_args), and codegen's existing C-string lending passes the NUL-terminated pointer. An unprototyped call keeps #1831's refusal. Fixture behav_2574.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions