From b308b8339709ca0177bab35690b822aca64cc51f Mon Sep 17 00:00:00 2001 From: Luca Toniolo <10792599+grandixximo@users.noreply.github.com> Date: Sat, 3 Oct 2026 11:48:49 +0800 Subject: [PATCH] hal: print 64-bit values and pointers without long long casts Use PRId64/PRIu64 for hal_sint/hal_uint values (halsh, halmeter, sampler_usr) and PRIxPTR for the rtapi_intptr_t function pointers in halcmd show funct. The macros pick the right specifier on LP64 and ILP32, so format and argument agree everywhere with no cast. Also fix signedness of the hm2_eth debug time prints (%lld, not %llu). --- src/hal/components/sampler_usr.c | 5 +++-- src/hal/drivers/mesa-hostmot2/hm2_eth.c | 8 ++++---- src/hal/utils/halcmd_commands.cc | 13 +++++++------ src/hal/utils/halsh.c | 5 +++-- src/hal/utils/meter.c | 7 ++++--- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/hal/components/sampler_usr.c b/src/hal/components/sampler_usr.c index 71d2abeaa9e..8f12bb8e184 100644 --- a/src/hal/components/sampler_usr.c +++ b/src/hal/components/sampler_usr.c @@ -60,6 +60,7 @@ */ #include +#include #include #include #include @@ -221,10 +222,10 @@ int main(int argc, char **argv) } break; case HAL_UINT: - printf ( "%llu ", (unsigned long long)buf[n].k); + printf ( "%" PRIu64 " ", buf[n].k); break; case HAL_SINT: - printf ( "%lld ", (long long)buf[n].l); + printf ( "%" PRId64 " ", buf[n].l); break; default: /* better not happen */ diff --git a/src/hal/drivers/mesa-hostmot2/hm2_eth.c b/src/hal/drivers/mesa-hostmot2/hm2_eth.c index 76766382041..3e49205e5f1 100644 --- a/src/hal/drivers/mesa-hostmot2/hm2_eth.c +++ b/src/hal/drivers/mesa-hostmot2/hm2_eth.c @@ -900,9 +900,9 @@ static int hm2_eth_read(hm2_lowlevel_io_t *this, rtapi_u32 addr, void *buffer, i t2 = rtapi_get_time(); if (recv == 4) { - LL_PRINT_IF(debug, "read(%d) : PACKET RECV [DATA: %08X | SIZE: %d | TIME: %llu]\n", board->read_cnt, *tmp_buffer, recv, t2 - t1); + LL_PRINT_IF(debug, "read(%d) : PACKET RECV [DATA: %08X | SIZE: %d | TIME: %lld]\n", board->read_cnt, *tmp_buffer, recv, t2 - t1); } else { - LL_PRINT_IF(debug, "read(%d) : PACKET RECV [SIZE: %d | TIME: %llu]\n", board->read_cnt, recv, t2 - t1); + LL_PRINT_IF(debug, "read(%d) : PACKET RECV [SIZE: %d | TIME: %lld]\n", board->read_cnt, recv, t2 - t1); } if (recv < 0) return 0; @@ -1035,7 +1035,7 @@ static int hm2_eth_receive_queued_reads(hm2_lowlevel_io_t *this) { return -EAGAIN; } - LL_PRINT_IF(debug, "receive_queued_reads(%d) : PACKET RECV [SIZE: %d | TIME: %llu]\n", board->read_cnt, recv, t2 - t1); + LL_PRINT_IF(debug, "receive_queued_reads(%d) : PACKET RECV [SIZE: %d | TIME: %lld]\n", board->read_cnt, recv, t2 - t1); for (i = 0; i < board->queue_reads_count; i++) { memcpy(board->queue_reads[i].buffer, &tmp_buffer[board->queue_reads[i].from], board->queue_reads[i].size); @@ -1154,7 +1154,7 @@ static int hm2_eth_send_queued_writes(hm2_lowlevel_io_t *this) { LL_PRINT("ERROR: sending packet: %s\n", strerror(errno)); } t1 = rtapi_get_time(); - LL_PRINT_IF(debug, "enqueue_write(%d) : PACKET SEND [SIZE: %d | TIME: %llu]\n", board->write_cnt, send, t1 - t0); + LL_PRINT_IF(debug, "enqueue_write(%d) : PACKET SEND [SIZE: %d | TIME: %lld]\n", board->write_cnt, send, t1 - t0); board->write_packet_ptr = board->write_packet; return send < 0 ? 0 : 1; } diff --git a/src/hal/utils/halcmd_commands.cc b/src/hal/utils/halcmd_commands.cc index 679c1605204..1e7775744e8 100644 --- a/src/hal/utils/halcmd_commands.cc +++ b/src/hal/utils/halcmd_commands.cc @@ -45,6 +45,7 @@ #include // rtapi_strlcpy #include +#include #include #include #include @@ -1704,18 +1705,18 @@ static void print_funct_info_print(const hal_query_t *q, const char **patterns) if(!match(patterns, q->name)) return; if(!scriptmode) { - halcmd_output(" %05d %08llx %08llx %-3s %5d %s\n", + halcmd_output(" %05d %08" PRIxPTR " %08" PRIxPTR " %-3s %5d %s\n", q->funct.comp_id, - (long long)q->funct.funct, - (long long)q->funct.arg, + q->funct.funct, + q->funct.arg, "YES", // Always uses FP q->funct.users, q->name); } else { - halcmd_output("%s %08llx %08llx %s %3d %s\n", + halcmd_output("%s %08" PRIxPTR " %08" PRIxPTR " %s %3d %s\n", q->funct.comp, - (long long)q->funct.funct, - (long long)q->funct.arg, + q->funct.funct, + q->funct.arg, "YES", // Always uses FP q->funct.users, q->name); diff --git a/src/hal/utils/halsh.c b/src/hal/utils/halsh.c index 38ba87dc461..b18989433e1 100644 --- a/src/hal/utils/halsh.c +++ b/src/hal/utils/halsh.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "halcmd.h" #include @@ -113,8 +114,8 @@ static int halsh_format_one(Tcl_Interp *interp, switch(hal_stream_element_type(s, idx)) { case HAL_BOOL: snprintf(buf, sizeof(buf), "%d", v.b ? 1 : 0); break; case HAL_REAL: snprintf(buf, sizeof(buf), "%g", v.f); break; - case HAL_SINT: snprintf(buf, sizeof(buf), "%lld", (long long)v.l); break; - case HAL_UINT: snprintf(buf, sizeof(buf), "%llu", (unsigned long long)v.k); break; + case HAL_SINT: snprintf(buf, sizeof(buf), "%" PRId64, v.l); break; + case HAL_UINT: snprintf(buf, sizeof(buf), "%" PRIu64, v.k); break; default: snprintf(buf, sizeof(buf), "0"); break; } Tcl_AppendElement(interp, buf); diff --git a/src/hal/utils/meter.c b/src/hal/utils/meter.c index 967ef4fce97..b911a6f0d56 100644 --- a/src/hal/utils/meter.c +++ b/src/hal/utils/meter.c @@ -50,6 +50,7 @@ #define _(x) gettext(x) #include +#include #include #include #include @@ -544,12 +545,12 @@ static const char *data_value(hal_type_t type, hal_refs_u ref) value_str = buf; break; case HAL_SINT: - snprintf(buf, sizeof(buf), "%10lld", (long long)hal_get_sint(ref.s)); + snprintf(buf, sizeof(buf), "%10" PRId64, hal_get_sint(ref.s)); value_str = buf; break; case HAL_UINT: { - unsigned long long v = hal_get_uint(ref.u); - snprintf(buf, sizeof(buf), "%10llu (0x%08llX)", v, v); + uint64_t v = hal_get_uint(ref.u); + snprintf(buf, sizeof(buf), "%10" PRIu64 " (0x%08" PRIX64 ")", v, v); value_str = buf; } break;