views:

118

answers:

1

I've recently had a question about coledatetime java implementation, and Chris said, that the problem might lay in type conversions: cpp-float vs java-float (Or maybe cpp-date vs java-date. Not types, but..). Now I have several questions on this:

  • Is there a table of comparison for java vs c++ types?
  • If type conversions is the problem, in my situation (I have a db with OLEDate records, already created with some c++ program. I need to read and write to that db, so that the OLEDate field compatibility remained: my java code reads proper dates, and c++ program is not affected with what the java program wrote to the db.), what would you do:
    • Use COleDateTime to retrieve the date with JNI?
    • Create your own implementation at all costs (using broader types, or anything else)?
  • Is there anything, I'm missing here?
+1  A: 

In c++ type ranges can and do differ from one implementation (compiler/architecture) to another, so there is no standard Java-C++ type comparisons as there is no standard C++ type sizes.

But in most current architectures C++ doubles are standard IEEE 754 doubles, as it is in Java. So while the code will not be strictly portable to some rare architecture, it will more often than not work in any x86/x86_64 architectures.

There was a question in the comments of the previous answer that you did not address: what is it that does not work in the implementation you have?

David Rodríguez - dribeas
So.. Does this mean, that COleDateTime is platform dependent in c++? I mean, if I compare float, that is returned from COleDateTime on x86 with the one, that I get on my x86_64, they shall be different even if both COleDateTime objects are constructed with exactly same dates?
folone
float and double are in x86 and x86_64 are the same types. Depending on the concrete operations you are performing and what processor you are running it in, the results might be slightly different due to rounding issues (you should never use direct equality comparisons with floating point data, but that is a different question), but with similar processors (say the same processor running 32 or 64 bit OS) the result should be consistent.
David Rodríguez - dribeas