-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Values, variables, pointers, and references (#2006)
Introduce a concrete design for how Carbon values, objects, storage, variables, and pointers will work. This includes fleshing out the design for: - The expression categories used in Carbon to represent values and objects, how they interact, and terminology that anchors on their expression nature. - An expression category model for readonly, abstract values that can efficiently support function inputs. - A customization system for value expression representations, especially as seen on function boundaries in the calling convention. - An expression category model for references instead of a type system model. - How patterns match different expression categories. - How initialization works in conjunction with function returns. - Specific pointer syntax, semantics, and library customization mechanisms. - A `const` type qualifier for use when the value expression category system is too abstracted from the underlying objects in storage. --------- Co-authored-by: Geoff Romer <gromer@google.com> Co-authored-by: josh11b <josh11b@users.noreply.github.com> Co-authored-by: Adrien Leravat <Pixep@users.noreply.github.com> Co-authored-by: Jon Ross-Perkins <jperkins@google.com> Co-authored-by: Richard Smith <richard@metafoo.co.uk>
- Loading branch information
1 parent
049fbc1
commit 0d1e6bd
Showing
12 changed files
with
2,446 additions
and
198 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Pointer operators | ||
|
||
<!-- | ||
Part of the Carbon Language project, under the Apache License v2.0 with LLVM | ||
Exceptions. See /LICENSE for license information. | ||
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
--> | ||
|
||
<!-- toc --> | ||
|
||
## Table of contents | ||
|
||
- [Overview](#overview) | ||
- [Details](#details) | ||
- [Precedence](#precedence) | ||
- [Alternatives considered](#alternatives-considered) | ||
- [References](#references) | ||
|
||
<!-- tocstop --> | ||
|
||
## Overview | ||
|
||
Carbon provides the following operators related to pointers: | ||
|
||
- `&` as a prefix unary operator takes the address of an object, forming a | ||
pointer to it. | ||
- `*` as a prefix unary operator dereferences a pointer. | ||
|
||
Note that [member access expressions](member_access.md) include an `->` form | ||
that implicitly performs a dereference in the same way as the `*` operator. | ||
|
||
## Details | ||
|
||
The semantic details of pointer operators are collected in the main | ||
[pointers](/docs/design/values.md#pointers) design. The syntax and precedence | ||
details are covered here. | ||
|
||
The syntax tries to remain as similar as possible to C++ pointer types as they | ||
are commonly written in code and are expected to be extremely common and a key | ||
anchor of syntactic similarity between the languages. | ||
|
||
### Precedence | ||
|
||
These operators have high precedence. Only [member access](member_access.md) | ||
expressions can be used as an unparenthesized operand to them. | ||
|
||
The two prefix operators `&` and `*` are generally above the other unary and | ||
binary operators and can appear inside them as unparenthesized operands. For the | ||
full details, see the [precedence graph](README.md#precedence). | ||
|
||
## Alternatives considered | ||
|
||
- [Alternative pointer syntaxes](/proposals/p2006.md#alternative-pointer-syntaxes) | ||
|
||
## References | ||
|
||
- [Proposal #2006: Values, variables, and pointers](/proposals/p2006.md) |
Oops, something went wrong.