Conversation
…ent format macros (i.e. PRId64)
|
I believe PR #187 should solve the code quality complaints |
|
let me know if I need to take a look |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes cross-platform printf format issues by replacing platform‐dependent specifiers (such as %ld and %lu) with standardized macros from <inttypes.h> (such as PRId64 and PRIu64). Key changes include:
- Updating printf and ERROR statements across multiple files to use portable format macros.
- Adjusting multi-line formatting in debug and error messages for improved readability.
- Ensuring consistent usage of format specifiers in both C and C++ code parts.
Reviewed Changes
Copilot reviewed 12 out of 19 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/test_dataStructure.c | Replaced %lu with "%" PRIu64 in test output. |
| libCacheSim/traceReader/customizedReader/lcs.c | Updated error and status messages to use portable format macros. |
| libCacheSim/mrcProfiler/mrcProfiler.h | Fixed format specifiers in printed output (using PRId64 for integer values). |
| libCacheSim/include/libCacheSim/reader.h | Reformatted multi-line comments and function signatures with no logic change. |
| libCacheSim/dataStructure/splay_tuple.c | Replaced legacy specifiers with standard macros in tree printing function. |
| libCacheSim/dataStructure/histogram.c | Updated CSV export format specifiers to use PRIu64. |
| libCacheSim/dataStructure/hashtable/chainedHashTableV2.c | Reformatted error messages and adjusted function signatures. |
| libCacheSim/cache/eviction/cpp/GDSF.cpp | Adjusted multi-line formatting and corrected format strings. |
| libCacheSim/cache/eviction/SLRUv0.c | Updated printf specifiers for object details to use PRId64. |
| libCacheSim/cache/eviction/LIRS.c | Corrected multiple printf format specifiers using PRId64 and PRIu64. |
| libCacheSim/cache/eviction/BeladySize.c | Reformatted function signatures and log messages with portable macros. |
| libCacheSim/cache/admission/adaptsize/adaptsize_interface.cpp | Updated admission interface debug prints to use PRIu64. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
There was a problem hiding this comment.
Bug: Inconsistent Format Specifiers for `obj_id`
The obj_id format specifier is inconsistent across printf statements. Line 714 uses PRId64 without casting for obj_id, while lines 723 and 733 incorrectly retain %ld with a (long) cast. This contrasts with obj_size, which was consistently updated to PRId64 on all three lines. All obj_id fields, being of the same type, should use a consistent format for portability.
libCacheSim/cache/eviction/LIRS.c#L713-L736
libCacheSim/libCacheSim/cache/eviction/LIRS.c
Lines 713 to 736 in 70e5820
Was this report helpful? Give feedback by reacting with 👍 or 👎
|
It looks like clang-format give a lot of errors, so revert for now, can you fix them? |



This PR fixes an issue related to Issue #182.
Issue
A common error reported by Clang is the use of incorrect format specifiers in the
printffunction. More specifically, an example of the error shown here shows that an argument of typeint64_tshould use the%lldformat specifier inprintfcalls:Fix
It turns out that format specifiers (i.e.
%lld) behave differently across platforms due to differences in how data types are defined and how format specifiers are interpreted (on Ubuntu/Linux,int64_trequires the%ldformat specifier). The solution for this is to use the format macros defined in<inttypes.h>, specificallyPRId64in this case - this expands to the correct format specifier depending on the platform and ensures that this is portable and has correct formatting across all systems.