Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No casting to a constant memory value

Status
Not open for further replies.

anxious7

Technical User
Nov 23, 2007
7
0
0
what should i do in order to avoid casting in this situation ?

(unknown data type) *ptr = 0x00102f3c;
 
Unless you're writing for DOS, or an embedded platform, why would you want to?


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
So what's the problem with using a cast?

You could hide it inside a macro, say
[tt]#define MK_PTR(x) ((void*)(x))[/tt]

Or maybe a short, possibly inline, function, say
Code:
void *mk_ptr ( unsigned long addr ) {
  return (void*)addr;
}

--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Maybe not, but before I think about some horribly contrived answer, why are you so against the idea of having just one cast to do one known thing?


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top