Hello, I've experience programming in C, but am new (somewhat) to C++. Please take a look at this snippet below. I haven't been active in C for a while, but would think it would work without the cast of (<type> *).
Am I remembering wrong, or, since I'm using a C++ compiler (G++, using Dev-C++), is that affecting the results?
#define BYTE unsigned char
#define ULONG unsigned long int
void POKE (ULONG *, BYTE);
BYTE PEEK (ULONG *);
int main(int argc, char *argv[])
{
int a=5;
ULONG *p_a;
char key;
p_a=(ULONG *)&a;
POKE(p_a, 0xff);
As it is, this compiles fine and works as I would expect. And for example, if I code:
p_a=(ULONG *)0x5000
this makes sense to me because I don't actually have an address of a variable for the variable reference operator &, so I should be stating p_a points to a ULONG , and not the value of 0x5000, but the cast by (ULONG *) is the address supplied.
But without the (<type> *) cast, I get an error compiling. Since I have a variable 'a' above (type int), shouldn't:
p_a=(ULONG)&a
suffice? What am I missing here? Am I losing my marbles, or just rusty with this stuff?
Thanks in advance.