Yarp: os/Stamp should be using a fixed size type for counter

Created on 16 Sep 2020  路  5Comments  路  Source: robotology/yarp

The yarp::os::Stamp class uses int to represent the counter.
Since int has a different representation depending on the system, it should be using a fixed size type, for example int32_t.

Also it should probably use an unsigned type, i.e. uint32_t

Library - YARP_os API Bug

Most helpful comment

@drdanz there are conditions where a negative counter (specifically -1) is employed to mean "invalid" or "not-available".

Exactly, if the Stamp is not defined it has -1 has seq number and 0.0 has ts, changing it would be a break of ABI

Ok for int32_t

All 5 comments

cc @Nicogene @traversaro

@drdanz there are conditions where a negative counter (specifically -1) is employed to mean "invalid" or "not-available".

Ok for int32_t 馃憤馃徎

@drdanz there are conditions where a negative counter (specifically -1) is employed to mean "invalid" or "not-available".

Exactly, if the Stamp is not defined it has -1 has seq number and 0.0 has ts, changing it would be a break of ABI

Ok for int32_t

Technically, if only -1 is used, it could be possible to use uint32_t and define

getMaxCount() == std::numeric_limits<uint32_t>::max() - 1;

since -1 has the exact representation as std::numeric_limits<uint32_t>

(btw getMaxCount should be constexpr)

since -1 has the exact representation as std::numeric_limits

Yeah, but then how this relates to checks like this below:

https://github.com/robotology/yarp/blob/71097ed9b24369d2709dc37298120130cc5c4868/src/libYARP_os/src/yarp/os/Stamp.cpp#L41-L44

If sequenceNumber is unsigned (likely it'll be changed to unsigned), then we need to change the check.
I'm afraid that similar checks might be spread around.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

diegoferigo picture diegoferigo  路  3Comments

xEnVrE picture xEnVrE  路  3Comments

S-Dafarra picture S-Dafarra  路  3Comments

drdanz picture drdanz  路  3Comments

CarlottaSartore picture CarlottaSartore  路  3Comments