Local * pLocal = *(Local**)0xE6EB54; // valid

How would u interpret these in english i understand it has to do with a pointer to a double pointer?

Local * pLocal = (Local**)0xE6EB54; // not sure if this is even valid

if the above is valid as well how would u interpret it?

7 Years
Discussion Span
Last Post by mike_2000_17

The above code is garbage and wont work for every compiler. Its trying to point to the address 0xE6EB54. Don't bother wasting your time with these nonsensical code.


>>Local * pLocal = *(Local**)0xE6EB54; // valid

English translation: Take the literal numeric value of the hexadecimal number E6EB54 and interpret that numeric value as the address of an address to an object of type Local. Dereference this numeric value to obtain value stored at the address it points to; that value is interpreted as the address of an object of type Local. Finally, store that address in a newly created variable called pLocal, of the same type.

NB: I guess you can see why we use a programming language to write programs, and not a regular language like English.. it would be much too verbose.

>>Local * pLocal = (Local**)0xE6EB54; // not sure if this is even valid

That's not valid, but this is: Local* pLocal = (Local*)0xE6EB56; .

Even if the above may compile (and are 'valid' in that sense), it doesn't mean that they are OK. In either cases 1 or 2, needless to say, the program will crash! You cannot just take some literal numeric value and fetch memory at that location, the OS forbids that (for many obvious and less obvious reasons). The only ways to get a valid pointer is by either taking the address of an object (with the & operator), or by getting a pointer in free-store (i.e. allocating a new chunk of memory with the 'new' operator, or equivalent).

Votes + Comments
roger that , well answered
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.