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

Revise general explanation on type casting #1354

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions p4-16/spec/P4-16-spec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3841,18 +3841,23 @@ Additionally, the maximum size of a variable-length bit-string can be determined
[#sec-casts]
=== Casts

P4 provides a limited set of casts between types. A cast is written
`(t) e`, where `t` is a type and `e` is an expression. Casts are only
permitted on base types and derived types introduced by `typedef`, `type`, and `enum`.
While this design is arguably more onerous for programmers, it has several benefits:
P4 provides a set of casts between types. A cast is written
`(t) e`, where `t` is a type and `e` is an expression. Casts in P4 are
permitted only under the conditions specified in section <<sec-explicit-casts>>
for explicit casts and section <<sec-implicit-casts>> for implicit casts.
By allowing casts only in limited scenarios, this restriction is more
onerous for programmers, but it also provides several benefits.
Comment on lines +3848 to +3849
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: maybe this would read more naturally:

Suggested change
By allowing casts only in limited scenarios, this restriction is more
onerous for programmers, but it also provides several benefits.
Allowing casts only in limited scenarios is more onerous for
programmers, but it also provides several benefits.


* It makes user intent unambiguous.
* It makes the costs associated with converting numeric values
explicit. Implementing certain casts involves sign extensions,
and thus can require significant computational resources on some targets.
* It reduces the number of cases that have to be considered in the P4
specification. Some targets may not support all casts.
specification.

Some targets may not support all casts.

[#sec-explicit-casts]
==== Explicit casts

The following casts are legal in P4:
Expand Down