Skip to content

translate-c: fix function pointer casting + alignCast and constCast at the same time #24546

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 2 commits into
base: master
Choose a base branch
from

Conversation

paokitore
Copy link

@paokitore paokitore commented Jul 22, 2025

This fixes #24513 and another issue I noticed: casting const void* to int* did not work.

Both of those issues are fixed with translate-c, so this PR might be useless though.

examples:

void *g = (void*)f;

used to translate to:

var g: ?*anyopaque = @as(?*anyopaque, @ptrCast(f));

forgetting a @constCast.

and

const void *c;
int *d = (int*)c;

the second line used to translate to:

var d: [*c]c_int = @as([*c]c_int, @ptrCast(@volatileCast(@constCast(c))));

forgetting a @alignCast.

@alexrp
Copy link
Member

alexrp commented Jul 22, 2025

This would effectively be made obsolete by #24497, so I think we'd only consider taking this PR if #24497 for some reason fails to land in 0.15.0.

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.

translate-c: cast function pointer to void pointer
2 participants