Skip to content

translate_c: fix ternary operator output in C macros #24664

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cmpute
Copy link

@cmpute cmpute commented Aug 2, 2025

this is a fix for #24590 . Basically it tries to wrap all the conditions in ternary operation with a zero check.

@Vexu
Copy link
Member

Vexu commented Aug 2, 2025

This version of translate-c is going to be deleted in favor of ziglang/translate-c: #24497. You should contribute this there instead.

@cmpute
Copy link
Author

cmpute commented Aug 3, 2025

This version of translate-c is going to be deleted in favor of ziglang/translate-c: #24497. You should contribute this there instead.

Per this comment: #24546 (comment), maybe let's see if this can land in 0.15?

@ehaas
Copy link
Contributor

ehaas commented Aug 3, 2025

Will this work if the check function returns a bool instead of int? I think full-featured support for the ternary operator in macros will require a helper function because any scalar type (ints, bools, floats, enums, pointers) can be used in the condition and the two result types are converted to a common type if necessary.

@cmpute
Copy link
Author

cmpute commented Aug 4, 2025

Will this work if the check function returns a bool instead of int? I think full-featured support for the ternary operator in macros will require a helper function because any scalar type (ints, bools, floats, enums, pointers) can be used in the condition and the two result types are converted to a common type if necessary.

This doesn't support other scalar types yet. It's also necessary to improve the ternary operator translation in normal (non-macro) code, which currently also uses the macroIntToBool function.

@cmpute
Copy link
Author

cmpute commented Aug 22, 2025

Any possibilities for this to be merged by the next minor version?

@Vexu Vexu added this to the 0.15.2 milestone Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants