Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inttypes.h-style printf format strings for common types #2010

Open
CDKnightNASA opened this issue Oct 26, 2021 · 2 comments
Open

inttypes.h-style printf format strings for common types #2010

CDKnightNASA opened this issue Oct 26, 2021 · 2 comments

Comments

@CDKnightNASA
Copy link
Contributor

Is your feature request related to a problem? Please describe.
For Message ID's, cFS generally use 0x%08X but sometimes it's printed with 0x%08x (lowercase a-f), or without the 0x, or even as %d or %u. (Although I don't know if that's used anymore.)

Describe the solution you'd like
Per https://en.wikipedia.org/wiki/C_data_types#Printf_and_scanf_format_specifiers C99 added printf format string macros for int types and it would be keen to follow this practice. I suggest PRIxMSG or PRIdMSG for printing (generally, sending an event message) a message ID in hex or decimal (defined as "0x%08X" and "%u" for unsigned integer (32-bit) MsgIds. So instead of:

...SendEvent(..."Error: unable to process message (MsgId=0x%08X)", MsgId)

it would be:

...SendEvent(..."Error: unable to process message (MsgId=" PRIxMSG ")", MsgId)

Describe alternatives you've considered
Leave well enough alone...:D

Additional context
Add any other context about the feature request here.

Requester Info
Christopher.D.Knight@nasa.gov

@skliper
Copy link
Contributor

skliper commented Oct 27, 2021

As long as it works everywhere I like this approach. Would really clean up our print formats (along with using the standard macros instead of doing casts everywhere which for some cases trigger static analysis warnings). We can define the custom macros with the typedef so they are easy to keep in sync, etc.

@astrogeco astrogeco added CCB:Ready Ready for discussion at the Configuration Control Board (CCB) and removed CCB:Ready Ready for discussion at the Configuration Control Board (CCB) labels Nov 3, 2021
@skliper
Copy link
Contributor

skliper commented Nov 3, 2021

Alternative - provide a "ToString" API? This then could avoid the messy format and the additional conversion from opaque (for opaque types). Another alternative is to preprocess the format string with custom values...

Example of local type where a ToString would help would be to convert CFE_Status_t would really help! And actually use it instead of printing an integer.

Could implemented using snprintf... or could have API's with common front end logging capability that you could specify where the message goes.

Non-opaque could use the standard values...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants