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

Reason for limiting fixed-length types to have a constant width #1228

Closed
pataei opened this issue Feb 14, 2023 · 5 comments
Closed

Reason for limiting fixed-length types to have a constant width #1228

pataei opened this issue Feb 14, 2023 · 5 comments

Comments

@pataei
Copy link
Contributor

pataei commented Feb 14, 2023

I'm wondering why P4 spec forces bit<W> or int<W> in some places, such as when they're used as the underlying type of a serializable enum or as the element type of a header. Why doesn't it just require a compile-time-known expression instead of a constant?

Also, does the use of W in spec always indicate a constant?

@vgurevich
Copy link
Contributor

vgurevich commented Feb 14, 2023

@pataei -- compile-time-known expressions are supported as type widths as long as you enclose them in parentheses. See Section 7.1.6.2 in the spec.

@mihaibudiu
Copy link
Contributor

it should be a compile-time known value in the spec.

This was referenced Mar 6, 2023
@pataei
Copy link
Contributor Author

pataei commented Mar 9, 2023

To double check my understanding, as an example, so there isn't anywhere in P4 that allows only bit<4> and not bit<(2+2)>, right?

@mihaibudiu
Copy link
Contributor

These two should be fully equivalent and can be used in the same contexts. See also #1213

@pataei
Copy link
Contributor Author

pataei commented Mar 14, 2023

Closing this after the merge.

@pataei pataei closed this as completed Mar 14, 2023
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

No branches or pull requests

3 participants