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
include
include
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
2 #include
3 #include
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.
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
include
include
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
2 #include
3 #include
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.