How to fix "used struct type value where scalar is required"?
c, if-statement, return-value
Solution
The expression `thread[j]` returns an instance of the struct `pthread_t`, which you can't use in a boolean context (e.g. in the context of an `if` statement). There's no reason you need that `if` statement anyway. Just say:
for (j = 0; j < n; j++) {
pthread_join(thread[j], NULL);
}
Problem
I keep getting this error when I compile and I cannot figure out why. The code block is: ``` static int run(int nm, int nf) { int i, j; int err, n = nm + nf; pthread_t thread[n]; for (i = 0; i < n; i++) { err = pthread_create(&thread[i], NULL, i < nm ? male : female, &shared_bathroom); if (err) { fprintf(stderr, "%s: %s: unable to create thread %d: %d\n", progname, __func__, i, err); return EXIT_FAILURE; } } for (j = 0; j < n; j++) { if (thread[j]) (void) pthread_join(thread[j], NULL); } return EXIT_SUCCESS; } ``` The error comes up for the line with the if statement under the second for loop. Specifically, I think it is referring to `(thread[j])`.