Skip to content

v: add support for alignof. #24509

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

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

v: add support for alignof. #24509

wants to merge 1 commit into from

Conversation

tritao
Copy link

@tritao tritao commented May 18, 2025

Summary

This PR adds support for the alignof builtin, allowing users to get the memory alignment (in bytes) of a type or expression.

Highlights

  • New AST node: AlignOf

  • Supports both alignof(expr) and alignof[Type]()

  • Integrated into:

    • Parser, checker, formatter (v fmt)

    • C codegen (via alignof(...) + <stdalign.h>)

    • JS backend (placeholder for now)

  • Updated docs.md and changelog

This improves low-level memory control and brings alignof in line with sizeof.

I know this is missing tests, just want to make sure this is acceptable to add before I put more time into it.

Copy link

Connected to Huly®: V_0.6-22877

@felipensp
Copy link
Member

Following this tip from CONTRIBUTING will helps you on next commits (it will do the v fmt on commit changed files to you):

cp cmd/tools/git_pre_commit_hook.vsh .git/hooks/pre-commit
chmod 755 .git/hooks/pre-commit

@tritao
Copy link
Author

tritao commented May 27, 2025

PR has been updated, can someone re-approve to run CI?

@enghitalo
Copy link
Contributor

PR has been updated, can someone re-approve to run CI?

You need to format the code use v fmt w . for this

@tritao
Copy link
Author

tritao commented May 27, 2025

v fmt w .

That wasn't it, I think the files should be already formatted through the setup Git pre-commit hook. I just had an unintended change in fmt.v.

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.

5 participants