Skip to content

Commit

Permalink
Merge branch 'vlang:master' into encoding.iconv
Browse files Browse the repository at this point in the history
  • Loading branch information
kbkpbot authored Sep 30, 2024
2 parents 06bd6f6 + aa3ab3f commit 462da8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -5953,9 +5953,10 @@ fn (mut g Gen) const_decl(node ast.ConstDecl) {
}
ast.StringLiteral {
val := g.expr_string(field.expr)
typ := if field.expr.language == .c { 'char*' } else { 'string' }
g.global_const_defs[util.no_dots(field.name)] = GlobalConstDef{
mod: field.mod
def: 'string ${const_name}; // a string literal, inited later'
def: '${typ} ${const_name}; // a string literal, inited later'
init: '\t${const_name} = ${val};'
order: -1
}
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/tests/consts/const_c_string_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const msg = c'test'

fn test_main() {
unsafe {
assert msg.vstring() == 'test'
}
}

0 comments on commit 462da8e

Please sign in to comment.