C Is Not Reasonable
osr.com
C Is Not Reasonable
1–10 of 71 posts
Re: C Is Not Reasonable
#2> ULONGLONG tableOffset;
It's starting well, for a C example...
Oh, and it ends even better:
> I write drivers for a living, not scientific or statistical analysis software. During this project, I quickly learn that casting everything to (double) was my friend. When in doubt, stick a (double) in front of it and test it again. In the end, the code worked pretty well. The customer was happy. We got paid.
o_O
OKOK, so you write drivers but don't know about C types, standard types, fixed-length types, you randomly fiddle with types until it passes a test but you don't know why it passes or doesn't, and you're proud of selling that.
Wonderful.
EDIT: added the "even better" part.
Re: C Is Not Reasonable
#3 ULONGLONG tableOffset;
tableOffset = (l1Index * L1_TABLE_GRANULARITY) +
(l2Index * L2_TABLE_GRANULARITY) +
startingL3->StartingOffset;
I'm tempted to point out that there's some HTML mishap, but actually the statement will be compiled if there is a variable called gt and one called StartingOffset.Re: C Is Not Reasonable
#4First line: > ULONGLONG tableOffset; It's starting well, for a C example... Oh, and it ends even better: > I write drivers for a living, not scientific or statistical analysis software. During this project, I quickly learn that casting everything to (double) was my friend. When in doubt, stick a (double) in front of it and test it again. In the end, the code worked pretty well. The customer was happy. We got paid. o_…
Re: C Is Not Reasonable
#5ok...
Re: C Is Not Reasonable
#6First line: > ULONGLONG tableOffset; It's starting well, for a C example... Oh, and it ends even better: > I write drivers for a living, not scientific or statistical analysis software. During this project, I quickly learn that casting everything to (double) was my friend. When in doubt, stick a (double) in front of it and test it again. In the end, the code worked pretty well. The customer was happy. We got paid. o_…
As someone who only has a passing knowledge of C, why is that wrong? Is it because it should be "uint_64" instead?
It does not remove the argument of C choosing to use the type of the operands to determine the width of the calculus, but it shown that this is not portable, standard C.
Also, if the guy writes drivers, you should expect him to be aware of these problems, possibly having built an extensive set of preprocessor macros to handle these problems, like all other drivers use. But he seems to just loop into the "modify /compile" until it compiles and behaves, without trying to understand.
Re: C Is Not Reasonable
#7If anyone could think of a good, concise way of expressing all these bells and whistles of arithmetic, it could be implemented as a language or language frontend. For now, most languages choose to either ignore it entirely or push the user to floating or arbitary-precision arithmetic as an 'improvement'.
Re: C Is Not Reasonable
#8First line: > ULONGLONG tableOffset; It's starting well, for a C example... Oh, and it ends even better: > I write drivers for a living, not scientific or statistical analysis software. During this project, I quickly learn that casting everything to (double) was my friend. When in doubt, stick a (double) in front of it and test it again. In the end, the code worked pretty well. The customer was happy. We got paid. o_…
As someone who only has a passing knowledge of C, why is that wrong? Is it because it should be "uint_64" instead?
Re: C Is Not Reasonable
#9Re: C Is Not Reasonable
#10With that exception, it's pretty much always assumed that an expression is evaluated independently of what it is being assigned to. I have a feeling that the author's preferred behavior would lead to some surprising results, but I can't think of any good examples off the top of my head.