On Thu, 2006-11-16 at 16:00 +1100, skaller wrote:
> I'm finally adding a new operator:
> This code compiles and gives the right result,
> then segfaults for an unknown reason.
Ah, I know the reason now: the constructor used was
_rtint(new_thing,0) // pointer, offset
Problem is the declaration is:
_rtint(void *f, int *d): _ref_(f,d){}
which is pointer/pointer format. This is an example
of the extreme stupidity of C, allowing integers and
pointers to silently convert. The base class allows:
_ref_(void *f, void *d):
frame(f), offset((unsigned char*)d-(unsigned char*)f) {}
_ref_(void *f, std::ptrdiff_t d):
frame(f), offset(d) {}
which is dang close to being ambiguous .. the derived class
eliminates the pointer/offset form. Unfortunately that is
required here: my fix to the generated code didn't segfault:
int *a = new(*PTF gc,int_ptr_map) int(PTF x);
PTF px = _rtint(a,a);
but there is no easy way to lift the code out like this
(even though it is a generator, and should only be used
as the RHS of an assignment/initialisation and not interior
to an expression, the code generator cannot easily do any lifts).
Anyhow the solution is just to add the right constructor:
_rtint(int *f): _ref_(f,std::ptrdiff_t(0)){}
and use that.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language