简体   繁体   English

在CORBA客户端/服务器应用程序中使用unsigned long(从C ++)到long(Java)?

[英]Assinging unsigned long (from C++) to long (Java) in CORBA client/server app?

On servers side I have function which returns unsigned long value (server is written in C++), lets say: 在服务器端,我有返回unsigned long值的函数(服务器是用C ++编写的),让我们说:

class Sth {

private:
   CORBA::ULong u;
public:
   CORBA::ULong get()
   {
    return this.u;
   }

};

How to assign (on clients side) value returned from server to variable? 如何分配(在客户端)从服务器返回到变量的值? I mean, theres no unsigned long in Java ... Is it possigle to assign it to long? 我的意思是,Java中没有unsigned long ...是否可以将它分配给long? Like this: 像这样:

// corba client stuff
long var = server_obj.get();

will it be ok? 会没事吗?

You have to look at the IDL mapping for that. 您必须查看IDL映射。 unsigned long of OMG IDLs mapped to CORBA::ULong in C++ and to int in Java. unsigned long的OMG IDL映射到C ++中的CORBA::ULong和Java中的int Refer IDL to Java Mapping and IDL to C++ Mapping for more on CORBA language mappings. 有关CORBA语言映射的更多信息,请参阅IDL到Java MappingIDL到C ++ Mapping

Try using the BigInteger class in java instead of long. 尝试在java中使用BigInteger类而不是long。 Theres not any other convenient way to make that conversion. 没有任何其他方便的方式来进行转换。

In many cases, you know that unsigned long will never exceed 2^31, aka MAX_LONG. 在许多情况下,你知道unsigned long永远不会超过2 ^ 31,即MAX_LONG。 Then using long in Java is okey. 然后在Java中使用long是很好的。

In some other cases, the actual values have little meaning, as long as they are unique, eg some kind of handle. 在其他一些情况下,实际值没有什么意义,只要它们是唯一的,例如某种句柄。 Again, you can use jlong. 再次,您可以使用jlong​​。

In yet other cases, Java is only used as an intermediate, and if conversion from C to Java to C is correct, you don't care that there was a signed/unsigned mismatch on the way. 在其他情况下,Java仅用作中间件,如果从C到Java到C的转换是正确的,那么您并不关心路上是否存在签名/未签名的不匹配。

But if none of the above exceptions hold, you should use BigInteger or reinvent it ( bad idea ) 但是,如果上述异常都没有,你应该使用BigInteger或重新发明它( 坏主意

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM