Skip to content

C2V does not translate parameters in main()  #180

@justinas

Description

@justinas
$ v version
V 0.4.6 fccd7cd

Given a C file that includes a function with the prototype int main(int argc, char **argv), V produces incorrect code referencing e.g. the argv array, but this array itself is nowhere to be found, so the generated V code does not compile

$ cat argv.c
#include <stdio.h>

int main(int argc, char **argv) {
  for (int i = 0; i < argc; i++) {
    puts(argv[i]);
  }
  return 0;
}
$ v translate argv.c
C to V translator 0.4.0
  translating /home/justinas/vlang-testcases/argv.c ... Reformatted file: /home/justinas/vlang-testcases/argv.v
 took   100 ms ; output .v file: argv.v
Translated   1 files in   100 ms.
$ cat argv.v
@[translated]
module main

fn main() {
        for i := 0; i < argc; i++ {
                C.puts(argv[i])
        }
        return
}
$ v run argv.v
argv.v:5:18: error: undefined ident: `argc`
    3 |
    4 | fn main() {
    5 |     for i := 0; i < argc; i++ {
      |                     ~~~~
    6 |         C.puts(argv[i])
    7 |     }
argv.v:6:10: error: undefined ident: `argv`
    4 | fn main() {
    5 |     for i := 0; i < argc; i++ {
    6 |         C.puts(argv[i])
      |                ~~~~
    7 |     }
    8 |     return
argv.v:6:14: error: type `void` does not support indexing
    4 | fn main() {
    5 |     for i := 0; i < argc; i++ {
    6 |         C.puts(argv[i])
      |                    ~~~
    7 |     }
    8 |     return
argv.v:6:10: error: `argv[i]` (no value) used as value in argument 1 to `C.puts`
    4 | fn main() {
    5 |     for i := 0; i < argc; i++ {
    6 |         C.puts(argv[i])
      |                ~~~~~~~
    7 |     }
    8 |     return

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions