jamesjuett / eecs280-async-lectures

MIT License
4 stars 2 forks source link

Lecture 5 Exercise 2.1 Mistake? #33

Closed sswangg closed 1 month ago

sswangg commented 1 month ago
Screenshot 2024-09-11 at 1 55 26 PM

In the walkthrough video, only red(arr1) is determined to be "sus". However, red and teal are both functions which take in a pointer. Really, 4 of these function calls are erroneous. Perhaps the sample code should be

int main() {
  const int arr1[6] = { ... };
  int arr2[6] = { ... };

  teal(&arr1);
  red(&arr1);
  purple(arr1[0]);

  teal(&arr2);
  red(&arr2);
  purple(arr2[0]);
}
jamesjuett commented 1 month ago

Thanks for reporting this issue!

It turns out that the exercise is well-formed, but it is out-of-date. I forgot to make an adjustment for this term. Prior to Fall 2024, EECS 280 used to cover raw arrays in C++, including a peculiar behavior called "array decay" where the compiler will insert an implicit conversion from an array to a pointer to its first element. So, an array of int may be passed to a function that takes an int * parameter, as in the exercise.

However, I had intended to update this exercise so that it didn't depend on arrays, since we haven't covered them yet. I'll fix this in a moment (while also configuring the exercise to accept any answers from the old version as well for participation credit).