From 9a6711fa1bb34aac0dd1244a4a2e1e4cb7cf53e1 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 4 Dec 2019 12:34:06 +0200 Subject: [PATCH] compiler: c'str' now has type charptr --- vlib/compiler/expression.v | 7 ++++++- vlib/compiler/tests/cstrings_test.v | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 vlib/compiler/tests/cstrings_test.v diff --git a/vlib/compiler/expression.v b/vlib/compiler/expression.v index 4117347743..b4884f1f10 100644 --- a/vlib/compiler/expression.v +++ b/vlib/compiler/expression.v @@ -167,10 +167,15 @@ fn (p mut Parser) name_expr() string { } // Raw string (`s := r'hello \n ') - if (name == 'r' || name == 'c') && p.peek() == .str && p.prev_tok != .str_dollar { + if name == 'r' && p.peek() == .str && p.prev_tok != .str_dollar { p.string_expr() return 'string' } + // C string (a zero terminated one) C.func( c'hello' ) + if name == 'c' && p.peek() == .str && p.prev_tok != .str_dollar { + p.string_expr() + return 'charptr' + } // known_type := p.table.known_type(name) orig_name := name is_c := name == 'C' && p.peek() == .dot diff --git a/vlib/compiler/tests/cstrings_test.v b/vlib/compiler/tests/cstrings_test.v new file mode 100644 index 0000000000..cc0ab5e810 --- /dev/null +++ b/vlib/compiler/tests/cstrings_test.v @@ -0,0 +1,9 @@ + +fn C.puts(charptr) int + +fn test_cstring(){ + h := c'world' + C.puts(c'hello') + C.puts(h) + assert true +}