Archived

This topic is now archived and is closed to further replies.

sunbeam60

Delphi dudes needs help with C variable types

Recommended Posts

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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites