|
|
Warp wrote:
> That's precisely what makes templates different from inheritance.
Yes, I know. But I appreciate the explanation. I understand it's merely
giving more information to the compiler so it can generate error
messages more easily, without actually changing the language.
(I'll also note there's a bunch of benefits to doing it the way Java
does that C++ templates can't support, too, having to do with strong
typing and dynamic loading and all that sort of stuff that C++ doesn't
do. But that's off topic.)
>> I was more amused by example of picking different operators to aid the
>> code generator in generating a more efficient operation for "+" than
>> anything, tho.
>
> I don't really understand what's so amusing with that. No compiler is
> perfect (regardless of language).
Sure, but if your compiler for your statically-typed language doesn't
know that for integral types
(x + x) is the same as (2 * x) is the same as (x << 1),
then I am not sure that writing macros to teach your compiler this is
the best use of your time, rather than finding a better compiler.
As I said, it was an overly-simplistic example that amused me. Entirely
appropriate for the article it was presented in. But it just twigged my
"low-level hackers live here" meme. Someone once asked me how you do a
"shift right by one byte" in Ada, and I said (x / 256). Someone else
commented "Wow, you really think in Ada!" I said "No, I write it the
same way in C and BASIC and Pascal, too."
--
Darren New / San Diego, CA, USA (PST)
Remember the good old days, when we
used to complain about cryptography
being export-restricted?
Post a reply to this message
|
|