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

Chapter 2: The Code in textbook not aligned with code linked #90

Open
Minho06 opened this issue Jan 12, 2024 · 0 comments
Open

Chapter 2: The Code in textbook not aligned with code linked #90

Minho06 opened this issue Jan 12, 2024 · 0 comments

Comments

@Minho06
Copy link

Minho06 commented Jan 12, 2024

In Chapter 2, the code in the free pdf of the textbook is not the same as the code linked to GitHub.
At ostep-code Github repository, ostep-code/intro/mem.c is written like this:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include "common.h"

int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "usage: mem \n");
exit(1);
}
int *p;
p = malloc(sizeof(int));
assert(p != NULL);
printf("(%d) addr pointed to by p: %p\n", (int) getpid(), p);
*p = atoi(argv[1]); // assign value to addr stored in p
while (1) {
Spin(1);
*p = *p + 1;
printf("(%d) value of p: %d\n", getpid(), *p);
}
return 0;
}

On textbook, the mem.c is written like this:
1 #include <unistd.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "common.h"
5
6 int
7 main(int argc, char *argv[])
8 {
9 int *p = malloc(sizeof(int)); // a1
10 assert(p != NULL);
11 printf("(%d) address pointed to by p: %p\n",
12 getpid(), p); // a2
13 *p = 0; // a3
14 while (1) {
15 Spin(1);
16 *p = *p + 1;
17 printf("(%d) p: %d\n", getpid(), *p); // a4
18 }
19 return 0;
20 }

The Github repository listed requires the mem.c to have an argument, the book doesn't require it.
It might be that the overall code on Github repository is different from the textbook.

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