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

Add the runtime parameter OPT__OUTPUT_TEXT_LENGTH_INT #407

Merged
merged 12 commits into from
Jan 16, 2025

Conversation

ChunYen-Chen
Copy link
Collaborator

Resolve #401.

@hyschive hyschive self-assigned this Jan 12, 2025
@hyschive hyschive added enhancement output Data output and log labels Jan 12, 2025
Copy link
Contributor

@hyschive hyschive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChunYen-Chen I have a potentially major concern about the incompatibility between different integer types (e.g., int and long) for variadic functions like printf(). For example, IIUC, the following code is invalid in general.

int a = 3;
printf( "%ld", a );

Given that OPT__OUTPUT_TEXT_FORMAT_INT can be set rather arbitrarily (e.g., %12ld, %12d, or %12u), it seems we cannot prevent such incompatibility issues from happening.

Possible solution:

  • Allow users to specify only the length of the integer output (e.g., OPT__OUTPUT_TEXT_LENGTH_INT = 12 )
  • Always assume a long integer (ld) in the format specifier of printf()
  • Explicitly cast integer arguments to long in function calls.

For example,

int temp = 3;
printf( "%*ld", OPT__OUTPUT_TEXT_LENGTH_INT, (long)temp );

What are your thoughts

Copy link
Contributor

@hyschive hyschive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Apply OPT__OUTPUT_TEXT_LENGTH_INT to Par_Output_TextFile.cpp

@ChunYen-Chen
Copy link
Collaborator Author

@hyschive Thanks for the review. I have updated the PR.

@hyschive hyschive changed the title Add a runtime parameter OPT__OUTPUT_TEXT_FORMAT_INT Add the runtime parameter OPT__OUTPUT_TEXT_LENGTH_INT Jan 16, 2025
@hyschive hyschive merged commit 40891ef into gamer-project:main Jan 16, 2025
@ChunYen-Chen ChunYen-Chen deleted the int_format branch January 22, 2025 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement output Data output and log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a runtime parameter OPT__OUTPUT_TEXT_FORMAT_INT
2 participants