1

我正在为操作系统 Rodos 实现从 C++ 到 Java 的通信接口。我的 C++ 有点“生锈”,而且我以前从未见过这个操作:header+0对于一个数组!

rodos/api/gateway/networkmessage.h:

class NetworkMessage {
    static const int HEADER_SIZE = 26;
    uint8_t header [HEADER_SIZE];
public:
    inline void    put_checkSum(uint16_t x)          {int16_tToBigEndian(header+0, x); }
    inline void    put_senderNode(int32_t x)         {int32_tToBigEndian(header+2, x); }

rodos/support_libs/stream-bytesex.cpp:

void int16_tToBigEndian(void* buff, uint16_t value) {
    uint8_t* byteStream = (uint8_t*)buff;
    if (byteStream == 0) return;
    byteStream[0] = (uint8_t) ((value >> 8) & 0xFF);
    byteStream[1] = (uint8_t) ((value >> 0) & 0xFF);
}

如何在 Java 中实现整数数组和整数的加法?

4

1 回答 1

1

C 中的数组主要是类型化指针的语法糖。对于T foo[...]声明,表达式foo + 2表示指向array 的第三个元素的指针foo

于 2013-11-14T19:47:08.810 回答