March 15, 2019
For today:
1) Read HFC Chapter 7
2) Finish Homework 6
3) Plan the end game of your project
Today:
1) const
2) Semaphores continued
3) HFC Chapter 7
4) Project time
For next time:
1) Read Think OS Chapter 7 and do the reading quiz
2) Prepare for a quiz
Project 1 due the evening of March 26
Read this article about the Const Qualifier in C
Benefits:
1) Declaring things const allows you to catch errors.
2) And it allows the compiler to do some optimizations.
But it is not a security feature that prevents abuse; it might save you from errors, but it is easy to subvert.
It's like putting an alarm on the refrigerator, not a lock.
Also, declaring a pointer to a structure const means that you cannot modify the struct using that pointer. But it does not make the struct itself immutable; you could still modify it using another pointer.
Good page to review:
My recommendation: Use fgets to get strings and do basic error checking.
Then parse the input as a separate step, possibly using sscanf.
Step 1: Use a library function, like qsort, that takes a function as a parameter.
Step 2: Write a function that takes a function as a pointer. The concept is simple, but the syntax is unpleasant.
Step 3: Profit.
This page might help: http://www.unixwiz.net/techtips/reading-cdecl.html
And you might want to bookmark this one: http://cdecl.org/
Try these examples from the book:
int (*match)(char*)
char** (*names_fn)(char*, int)
int (*compar)(const void *, const void *)
void (*qsort)(void *,
size_t,
size_t,
int (*compar)(const void *, const void *))
Note: the last one is correct, but seems to break cdecl.org!
See if you can figure out this one: char *(*(**foo[][8])())[]
Then use cdecl.org to check.
Finally, let's do the exercises on page 328 and 329 of HFC.