From: Carlos H. C. <fb...@wa...> - 2004-07-29 17:48:02
|
I'm trying to convert some functions in fbudf.cpp to Delphi code, and now, after many years without looking at C code (since university), I now remember clearly why I hate it :-) void set_double_type(paramdsc* v, const double iv) { switch(v->dsc_dtype) { case dtype_real: *reinterpret_cast<float*>(v->dsc_address) = static_cast<float>(iv); break; case dtype_double: *reinterpret_cast<double*>(v->dsc_address) = iv; break; } } In Pascal, something like: procedure Set_Double_Type(P: PParamDsc; const Value: Double); begin case P.dsc_dtype of dtype_real: PFloat(P.dsc_address)^:=Single(Value); dtype_double: PDouble(P.dsc_address)^:=Value; end; end; Problem is: Delphi does not accept a cast like Single(Value), mostly because Double is 8 bytes and Single is 4 bytes. Does anybody knows how would be the safe way of doing that in Delphi? []s Carlos http://www.warmboot.com.br FireBase - http://www.FireBase.com.br |