Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C2V does not translate parameters in main() #180

Open
justinas opened this issue Jun 28, 2024 · 0 comments
Open

C2V does not translate parameters in main() #180

justinas opened this issue Jun 28, 2024 · 0 comments

Comments

@justinas
Copy link

$ 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant