Skip to content

Passing to C issue #23973

Description

@antono2

Describe the bug

Here https://github.com/antono2/tmp/blob/603637399d22d4205af468cd6b634f2f64eefdb1/main.v#L118 I'd like to pass a pointer to C, but get

error: invalid initializer
 6334 |         main__Struct_array __tmp_arg_1 = param;

And using C.struct_array instead of alias

error: unknown type name ‘C__struct_array’; did you mean ‘struct_array’?
 6334 |         C__struct_array __tmp_arg_1 = param;

Reproduction Steps

git clone --depth=1 https://github.com/antono2/tmp && cd tmp && git checkout 603637399d22d4205af468cd6b634f2f64eefdb1 && v -show-c-output -cc gcc run .

Expected Behavior

Call set_struct_array in include/array.c

Current Behavior

/tmp/v_1000/tmp.01JPPP02KCQ7864DRP1NQT4M0Q.tmp.c: In function ‘main__set_struct_array’:
/tmp/v_1000/tmp.01JPPP02KCQ7864DRP1NQT4M0Q.tmp.c:6334:42: error: invalid initializer
 6334 |         main__Struct_array __tmp_arg_1 = param;
      |                                          ^~~~~
/tmp/v_1000/tmp.01JPPP02KCQ7864DRP1NQT4M0Q.tmp.c:6335:26: error: incompatible type for argument 1 of ‘set_struct_array’
 6335 |         set_struct_array(__tmp_arg_1);
      |                          ^~~~~~~~~~~
      |                          |
      |                          main__Struct_array {aka struct_array}
/home/anton/workspace/tmp/include/array.c:132:32: note: expected ‘struct_array *’ but argument is of type ‘main__Struct_array’ {aka ‘struct_array’}
  132 | set_struct_array(struct_array* param)
      |                  ~~~~~~~~~~~~~~^~~~~

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.9 b528395

Environment details (OS name and version, etc.)

V full version V 0.4.9 9921692.b528395
OS linux, Ubuntu 24.04.2 LTS
Processor 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
Memory 0.44GB/15.56GB
V executable /home/anton/workspace/v/v
V last modified time 2025-03-19 02:20:05
V home dir OK, value: /home/anton/workspace/v
VMODULES OK, value: /home/anton/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/anton
Git version git version 2.43.0
V git status weekly.2025.08-198-gb5283950
.git/config present true
cc version cc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
gcc version gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
clang version clang version 21.0.0git (https://github.com/llvm/llvm-project.git bd034ab1113cd3705fedf75d870dc4b7388d8f70)
tcc version tcc version 0.9.28rc 2024-07-31 HEAD@1cee0908 (x86_64 Linux)
tcc git status thirdparty-linux-amd64 0134e9b9-dirty
emcc version N/A
glibc version ldd (Ubuntu GLIBC 2.39-0ubuntu8.4) 2.39

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

Labels

BugThis tag is applied to issues which reports bugs.Unit: cgenBugs/feature requests, that are related to the default C generating backend.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions