Nov 23, 2007 #1 anxious7 Technical User Joined Nov 23, 2007 Messages 7 what should i do in order to avoid casting in this situation ? (unknown data type) *ptr = 0x00102f3c;
what should i do in order to avoid casting in this situation ? (unknown data type) *ptr = 0x00102f3c;
Nov 23, 2007 #2 Salem Programmer Joined Apr 29, 2003 Messages 2,455 Location GB 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. Upvote 0 Downvote
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.
Nov 23, 2007 Thread starter #3 anxious7 Technical User Joined Nov 23, 2007 Messages 7 it's for an embedded system Upvote 0 Downvote
Nov 23, 2007 #4 Salem Programmer Joined Apr 29, 2003 Messages 2,455 Location GB 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. Upvote 0 Downvote
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.
Nov 23, 2007 Thread starter #5 anxious7 Technical User Joined Nov 23, 2007 Messages 7 is casting inevitable ? Upvote 0 Downvote
Nov 23, 2007 #6 Salem Programmer Joined Apr 29, 2003 Messages 2,455 Location GB 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. Upvote 0 Downvote
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.