Delphi dudes needs help with C variable types

Started by
4 comments, last by sunbeam60 23 years, 10 months ago
Hi I''m trying to convert some Alpha-blending code snippets I found in C++ to Object Pascal, i.e. Delphi. However I grind to a halt upon the C/C++ variable type ''word''. In Delphi a word is a two byte, unsigned integer type. I''ve tried to dig up my old text-book on C, but the variable type ''word'' goes unmentioned, so I assume ''word'' is non ANSI. Whatever it is, I went along and translated it into a Delphi word, but suddenly I stumbled upon these C statements: WORD ALPHA; DWORD ALPHABY4; ALPHABY4 = (ALPHA / 4) / ((ALPHA / 4) << 16); In which ALPHA gets divided by 4. What the heck? I know C/C++ isn''t as type-stringent as Delphi, but how can an integer type be divided by 4? SO, I must assume that a WORD isn''t what I thought it was. Any help would be gladly appreciated. btw: Did you notice how I chose the we-live-in-peace-and-harmony-yin-and-yan-symbol to defer any flames about which language is better than the other Regards Toft
Advertisement
The WORD type is defined in the standard windows include files that ship with MSVC. It''s actually an unsigned short, which is an unsigned 16 bit value. And what do you mean by dividing an integer by 4. Any integer can be divided by 4. I believe the returned result is just rounded...
Where Delphi oddly uses both the / symbol and the keyword div for floating point and integer operations (respectively), C/C++ uses just the / symbol, and uses a little brain-power. ;-)

It''s one of Delphi''s pointless language quirks (like disallowing a semicolon before a then keyword, which it in itself is pointless).

Basically, you''d translate that to:

ALPHABY4 := (ALPHA div 4) div ((ALPHA div 4) shl 16);

I haven''t tested that though.
Creativity is a bloody nuisance and an evil curse that will see to it that you die from stress and alcohol abuse at a very early age, that you piss off all your friends, break appointments, show up late, and have this strange bohemian urge (you know that decadent laid-back pimp-style way of life). The truly creative people I know all live lousy lives, never have time to see you, don't take care of themselves properly, have weird tastes in women and behave badly. They don't wash and they eat disgusting stuff, they are mentally unstable and are absolutely brilliant. (k10k)
thanks for the help

Although I can''t help smiling when reading Revolvers remarks about Delphi vs. C++

I knew it

Celebrityyyyyyyy deathmaaaaaaaaaatch featuring
In the left corner, weighing 225 punds, he''s been around for some time, iiiiiiits no other than Mr. C PLUS PLUS
And in the right corner, weighing only 210 punds, but with an irritating ability to show his face where nobody wants it, iiiiiiiits Delphi!

Regards
Toft
Please don''t take that as Delphi bashing. I''m fluent in both C++ and Delphi (Object Pascal), as well as numerous other languages. ;-)

I use Delphi a LOT at work (business applications). It''s quite an amazing development environment - the compiler is faster than compilers in many other languages, even when it''s processing a great deal more lines of code. The compiler is also very good at producing very fast, optimized machine code. The speed, coupled with VCL technology is just plain amazing. The language itself has come a long, long way from the original Pascal specifications (the addition of classes, overridable member functions, etc. etc.) such that it supports much the same things that C++ does (and at least one thing it doesn''t - nested functions), but still has some quirky hold-overs that I''d like to see banished. ;-)

I do however, use C++ for graphics and game development, as the language is as perfectly suited for it as any I''ve seen. I prefer C++ class functionality to that of Delphi, though it''s not that greatly different. As well, the syntax seems a bit more logical to me (i.e., no need for completely unnecessary keywords or punctuation, like you find in a few instances in Object Pascal).
Creativity is a bloody nuisance and an evil curse that will see to it that you die from stress and alcohol abuse at a very early age, that you piss off all your friends, break appointments, show up late, and have this strange bohemian urge (you know that decadent laid-back pimp-style way of life). The truly creative people I know all live lousy lives, never have time to see you, don't take care of themselves properly, have weird tastes in women and behave badly. They don't wash and they eat disgusting stuff, they are mentally unstable and are absolutely brilliant. (k10k)
Yeah, well; Some Delphi bashing might be a good idea, though.

I finished converting the C code to Pascal, but to my dismay, the results are awful.

The code is taken from John Hebert''s article here on gamedev.net, but I, i.e. the Delphi code, get nowhere near the results that the C code delivers.

I''ve started another thread on this subject (Is it me or did Delphi just bomb?!) here on the boards, so if anyone reading these posts feel the urge to go comment on my conversion, I''d appreciate it.

Thanks in advance
Toft

This topic is closed to new replies.

Advertisement