Page 1 of 1
Stupidest Programming Mistakes?
Posted: Fri Mar 05, 2004 5:48 pm
by VLSmooth
Code: Select all
// debug: print out vector
for (vector<int>::iterator iter = someVector.begin();
iter != someOtherVector.end();
++iter) {
printf("%d\n", *iter);
}
Anyone see a problem? I feel extremely stupid right now... (took 2.5 days to track down...)
Example has been intentionally generalized with extra vagueness
Posted: Fri Mar 05, 2004 5:52 pm
by Peijen
I don't see what's wrong with the code, some time you need to know where the value is point to
Posted: Fri Mar 05, 2004 5:55 pm
by VLSmooth
Notice
and
I intended to print out all the elements in someVector...
more background:
someVector = class attribute
someOtherVector = input parameter (was a vector)
Granted, this was one error in 52 files I modified...
* VLSmooth smacks himself again
Posted: Wed Mar 10, 2004 9:27 pm
by Peijen
Code: Select all
SQLBindCol(sql_h_list_stmt, 1, SQL_C_TCHAR, &rate_table_name, 64*tchar_size, &dummy);
SQLBindCol(sql_h_list_stmt, 2, SQL_C_SHORT, &rate_table_code, 0, &dummy);
SQLBindCol(sql_h_list_stmt, 3, SQL_C_SHORT, &age_size, 0, &dummy);
SQLBindCol(sql_h_list_stmt, 4, SQL_C_SHORT, &dur_size, 0, &dummy);
sql_query = L"SELECT rate_table_code, rate_table_name, age, duration FROM lRateTableList;";
...
Posted: Wed Mar 10, 2004 9:51 pm
by Jonathan
age_size is not the same as age and dur_size is not the same as duration?
Posted: Wed Mar 10, 2004 10:40 pm
by Peijen
(rate_table_name, rate_table_code) ordering between the bind and actual select statment
took me 3 hours ...
Posted: Thu Mar 18, 2004 2:08 am
by Jonathan
I don't think anyone will be able to catch this one, because the bug is in the intentions of the programmer, not the code.
Original:
Code: Select all
mask = generate_mask(num_bits)<<(bits_used - (one_bit_overlap ? 1 : 0));
I tried to add the possibility of a two_bit_overlap.
Changed to:
Code: Select all
mask = generate_mask(num_bits)<<(bits_used - (one_bit_overlap ? 1 : 0) - (two_bit_overlap ? 1 : 0));
Posted: Thu Mar 18, 2004 3:10 am
by quantus
Dwindlehop wrote:I don't think anyone will be able to catch this one, because the bug is in the intentions of the programmer, not the code.
Original:
Code: Select all
mask = generate_mask(num_bits)<<(bits_used - (one_bit_overlap ? 1 : 0));
I tried to add the possibility of a two_bit_overlap.
Changed to:
Code: Select all
mask = generate_mask(num_bits)<<(bits_used - (one_bit_overlap ? 1 : 0) - (two_bit_overlap ? 1 : 0));
Ok, lemme guess, you thought you were using one-hot coding when you implemented the part determining what to set one_bit_overlap and two_bit_overlap to. Meanwhile, you are checking it in such a way that if two_bit_overlap is set, one_bit_overlap is expected to be set as well. So in short, you didn't keep your coding schemes in sink? Is that about right?
Posted: Thu Mar 18, 2004 5:42 pm
by VLSmooth
In short, did you want this?
Code: Select all
mask = generate_mask(num_bits)<<(bits_used - (two_bit_overlap ? 2 : (one_bit_overlap ? 1 : 0)));
In other words,
Code: Select all
if (two_bit_overlap) {
return 2;
} else if (one_bit_overlap) {
return 1;
} else {
return 0;
}
Since, as Joe also pointed out, you never guaranteed the status of one_bit_overlap when two_bit_overlap is set.
ps. Intentions of the programmer equates to your semantics correct? (Which aren't given, hence it's impossible to determine if we're correct, on even on track. whee~)
Posted: Thu Mar 18, 2004 6:24 pm
by Jonathan
Impressive.
That is largely correct. two_bit_overlap only has meaning if one_bit_overlap is asserted. When one_bit_overlap is false and two_bit_overlap is true, the correct behavior is to have zero overlap.
I had to run a regression to catch that one.
Posted: Thu Mar 18, 2004 7:46 pm
by VLSmooth
Ah, so:
Code: Select all
mask = generate_mask(num_bits)<<(bits_used - (one_bit_overlap ? (two_bit_overlap ? 2 : 1) : 0));
Code: Select all
if (one_bit_overlap) {
if (two_bit_overlap) {
return 2;
} else {
return 1;
}
} else {
return 0;
}
Posted: Thu Mar 18, 2004 8:12 pm
by Jonathan
Indeed.
Posted: Sat Apr 17, 2004 12:57 am
by Jonathan
I still can't figure out why this makes bar = 7 for all values of x that I tested.
Posted: Sat Apr 17, 2004 1:14 am
by quantus
what values of x did you test? 7,15,47, etc?
Posted: Sat Apr 17, 2004 1:24 am
by Jonathan
outputs of a function.