Compare pointer to given value in C++ -


i'm on amd64 architecture. following code gets rejected g++ compiler @ "if" statement:

void * newmem=malloc(n); if(newmem==0xefbeaddeefbeadde){ 

with error message:

error: iso c++ forbids comparison between pointer , integer [-fpermissive] 

i can't seem find magic incantation needed going (and don't want use -fpermissive). appreciated.

background: i'm hunting ugly bug crashes program while requesting memory in stl new operation (at least gdb told me that). thinking memory overrun of 1 of allocated memory chunks being, bad luck, adjacent memory used os manage memory lists of program, overrode new(), new plus delete counterparts own routines added memory fencing; , while application still crashes (all fences intact (sigh)), gdb told me this:

program received signal sigsegv, segmentation fault. 0x0000000000604f5e in construct (__val=..., __p=0xefbeaddeefbeadde, this=<optimized out>) @ /usr/include/c++/4.6/ext/new_allocator.h:108 108 { ::new((void *)__p) _tp(__val); } 

i noted pointer __p has value pointer representation of value used 1 of memory fences (0xdeadbeef), hence wish catch earlier in new() try , dump out more complex values in program.

additional note: function crashes runs flawlessly couple of million times before crashes (intermixed dozens of other routines run couple of thousand million times), using valgrind not seem option atm because takes 6hrs , 11 gb before program crashes.

one of them integer, , other pointer. perhaps ugly cast do

if(newmem==(void*)0xefbeaddeefbeadde){ 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -