1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

doc: document C string literals

This commit is contained in:
Alexander Medvednikov 2020-07-23 22:49:56 +02:00 committed by GitHub
parent 32c1042ac6
commit 2eee274d6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1964,9 +1964,9 @@ fn my_callback(arg voidptr, howmany int, cvalues &charptr, cnames &charptr) int
}
fn main() {
path := 'users.db'
db := &C.sqlite3(0) // a temporary hack meaning `sqlite3* db = 0`
C.sqlite3_open(path.str, &db)
db := &C.sqlite3(0) // this means `sqlite3* db = 0`
C.sqlite3_open('users.db', &db) // passing a string literal to a C function call results in a C string, not a V string
// C.sqlite3_open(db_path.str, &db) // you can also use `.str byteptr` field to convert a V string to a C char pointer
query := 'select count(*) from users'
stmt := &C.sqlite3_stmt(0)
C.sqlite3_prepare_v2(db, query.str, - 1, &stmt, 0)