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

Example from tutorial doesn't work. Why? #3

Open
zeleniy opened this issue Nov 15, 2024 · 1 comment
Open

Example from tutorial doesn't work. Why? #3

zeleniy opened this issue Nov 15, 2024 · 1 comment

Comments

@zeleniy
Copy link

zeleniy commented Nov 15, 2024

Hello! I get very first example from here and get en error:

$ ls
bcause  examples  libb.a  libb.o  LICENSE  Makefile  README.md  src
$ cat ~/b/putnumb.b
main() {
  auto a, b, c, sum;

  a = 1; b = 2; c = 3;
  sum = a+b+c;
  putnumb(sum);
}
$ ./bcause ~/b/putnumb.b
./bcause: error: undefined identifier ‘putnumb’

Why library function putnumb is undefined? What's wrong?

@Spydr06
Copy link
Owner

Spydr06 commented Nov 16, 2024

first, you have to tell the compiler, that putnumb exists, you can do that by adding

extrn putnumb;

to the start of your main() function.

Secondly, you have to define putnumb somewhere, as this is not a function found in B's standard library. Maybe putnumb isn't listed in the B reference, in that case you're welcome to implement it yourself into src/libb/libb.c :D

Or you replace putnumb(sum) with printf("%d*n"). Then your program would look like:

main() {
    extrn printf;
    auto a, b, c, sum;

    a = 1; b = 2; c = 3;
    sum = a + b + c;
    printf("%d*n", sum);
}

I tested this and it seems to work as expected.

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

2 participants