some porting to VC++ (incomplete due to a compiler bug)