J
Jeff Schwab
Julian said:Can anybody help me to translate the following lines to pascal(delphi)?
Let me explain what I'm looking for:
int i = 1; {In this line, an integer variable which is called "i" is
declared and it is initialised with 1}
BYTE data[2000]={0}; {your comments here...}
Create an array of 2000 elements (of type BYTE) on the stack. Set the
first element to 0. That may not be what the author meant, but that's
probably what he got.
BITMAPINFOHEADER *bh=(BITMAPINFOHEADER*)data; {your comments here...}
Pointers are variables that hold memory addresses. This line defines a
pointer (called "bh") to hold the address of an existing variable called
"data." This is an ancient, and particularly unhelpful, style of C++.
RGBQUAD *pal=(RGBQUAD*)(data+sizeof(*bh)); {your comments here...}
This seems to define another pointer ("pal") to point somewere in the
middle of "data." The author may have been trying to access individual
members of an aggregate data structure. This does not appear to be very
good code.
I am very confused with the meaning that has the * in C/C++
I don't understand why it precedes the variable/type in some cases and in
other cases it is later
I'm sorry to have to tell you this, but C++ syntax blows. Most of it
was inherited from C. Syntax is generally considered the one big weak
spot of C++.
Neither I understand this kind of lines:
(BITMAPINFO*)bh {a type cast?}
You got it. That line means "let's pretend that bh is a pointer holding
the address of some BITMAPINFO, whether it is not."
&specbuf {the data referenced by a Pointer variable?}
Close. The "&", or "address-of" operator, gives the location of a
variable in memory.
TIA.
Hope this helps,
Jeff