4 ms·
At least once a quarter I'd have a student working on some programming assignment on one of our unix-ish systems where they named the executable "test" and coul
by ja27 14y ago
At least once a quarter I'd have a student working on some programming assignment on one of our unix-ish systems where they named the executable "test" and couldn't figure out why it wasn't doing anything they expected.
I also got to the point with FORTRAN (yes, I'm old) students where I'd cut them off and tell them to count the columns and make sure each line started with 6 blanks, not 5.
My favorite bug is still some piece of C code buried in a library that was like this:
if (flag == TRUE) ...
Or there's the old for loop typo (much easier to detect on today's high-DPI screens):
for(float x=0.0; x < 3,4; x = x + 0.1) ...
- viraptor 14y agoI don't get what's wrong with the flag check apart from being a bit too verbose.
- mpyne 14y agoTRUE is going to be 1. The flag value might have the value 0x2, 0x4, 0xsomething_else, etc., which will not equal exactly 1 (TRUE). What you want varies but is probably something like: if (flag & FLAG_VALUE) ... if (flag) .... if ((flag & FLAG_VALUE) == TRUE) ... that kind of thing.
- geon 14y agoif ((flag & FLAG_VALUE) == TRUE) ... That would still check if flag is 1, right?
- to3m 14y agoflag&FLAG_VALUE will be FLAG_VALUE or 0, so unless FLAG_VALUE==TRUE the answer could be wrong. Suggest (flag&FLAG_VALUE), or, if you need the expression to be of type bool, ((flag&FLAG_VALUE)!=0) or (!!(flag&FLAG_VALUE)).
- mpyne 14y agoVery true, I just checked to see if I can edit but I can't, so mea culpa.
- ja27 14y agoBoolean true / TRUE wasn't defined in any standard way before C99. Back in the "olden days", most programmers #defined it as 1, but not always. I ran into one of those "not always" cases in some inherited code.
- anonymouz 14y agoI'm curious about the test one. Do you have "." in your PATH? Or do students simply not realize that they should call their program as ./test anyway?
- ja27 14y agoStudent accounts had "." in their PATH by default. I'm sure someone did it to keep students from asking why their program wouldn't run at all. Fun times.