Skip to content

Commit 305c56d

Browse files
committedFeb 11, 2025··
cgen: fix #preinclude, add test case for #postinclude too
1 parent d82757a commit 305c56d

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed
 

‎vlib/v/gen/c/cgen.v

+1
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO
570570
}
571571
b.write_string2('\n// V comptime_definitions:\n', g.comptime_definitions.str())
572572
b.write_string2('\n// V typedefs:\n', g.typedefs.str())
573+
b.write_string2('\n // V preincludes:\n', g.preincludes.str())
573574
b.write_string2('\n// V cheaders:', g.cheaders.str())
574575
if g.pcs_declarations.len > 0 {
575576
b.write_string2('\n// V profile counters:\n', g.pcs_declarations.str())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hi from V, p: 42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module no_main
2+
3+
#postinclude "@VEXEROOT/vlib/v/gen/c/testdata/postinclude_header.h"
4+
5+
@[markused]
6+
pub fn f(p int) int {
7+
assert p == 42
8+
C.printf(c'Hi from V, p: %d\n', p)
9+
return 987
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <assert.h>
2+
3+
int main( void ) {
4+
int res = no_main__f(42);
5+
assert(res == 987);
6+
return 0;
7+
}

0 commit comments

Comments
 (0)
Please sign in to comment.