Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
thradams committed Jan 1, 2025
1 parent cd2e3c0 commit 30cea19
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 15 deletions.
66 changes: 61 additions & 5 deletions ownership.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ void f() {
<button onclick="Try(this)">try</button>
In some cases it may be useful to make the non-nullable members as nullable. Applying `_Opt` qualifier to structs makes all members nullable.
In some cases it may be useful to make the non-nullable members as nullable.
Applying `_Opt` qualifier to structs makes all members nullable.
For instance, the previous calloc sample can be written as.
Expand All @@ -322,11 +323,67 @@ void f() {

<button onclick="Try(this)">try</button>


Adding the `_Opt` qualifier in front of `struct X` (as in `_Opt struct X x;`) is analogous to
changing the type of `x` from:

```c
struct X { char * text; };
```
to:
```c
struct X { char * _Opt text; };
```

This can be compared to the addition of the `const` qualifier.
For example:

```c
const struct X x;
```

The type of `x` in this case is similar of to changing from:

```c
struct X { char * text; };
```
to:
```c
struct X { char * const text; };
```

We will discuss later another situation involving the `_View` qualifier that works as anti-owner qualifier.


#### mutable

In the same way we removed the implicit non-nullable qualifier, we also could remove the const qualifier. The anti const qualifier could be named as `mutable`.
In the same way we removed the implicit non-nullable qualifier, we also could remove the const qualifier.
The anti const qualifier could be named as `mutable`.

For instance:

```c
struct X { char * const text; };
```
The declaration
```c
mutable struct X x;
```

could be similar of having the type of `x` as:

```c
struct X { char * text; };
```
But instead of having anti-const and anti-non-nullable qualifier the mutable has been considered to remove both.
But instead of having anti-const and anti-non-nullable qualifier the mutable has been
considered to remove both because they may happen together.
Consider the following code example:
Expand All @@ -350,9 +407,8 @@ struct X * _Opt makeX(const char* name)
}
```

>OBS: mutable qualifier is not yet implemented.
>OBS: mutable qualifier is not yet implemented in Cake.
Note: The syntax used in the C++ 26 proposal for contracts may be utilized in the future to eliminate the need for built-in semantics for `malloc` and `calloc`.

### Object lifetime checks
From the C23 standard:
Expand Down
70 changes: 69 additions & 1 deletion src/web/default.min.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,72 @@
Website: https://highlightjs.org/
License: see project LICENSE
Touched: 2021
*/pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{background:#f3f3f3;color:#444}.hljs-comment{color:#697070}.hljs-punctuation,.hljs-tag{color:#444a}.hljs-tag .hljs-attr,.hljs-tag .hljs-name{color:#444}.hljs-attribute,.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-name,.hljs-selector-tag{font-weight:700}.hljs-deletion,.hljs-number,.hljs-quote,.hljs-selector-class,.hljs-selector-id,.hljs-string,.hljs-template-tag,.hljs-type{color:#800}.hljs-section,.hljs-title{color:#800;font-weight:700}.hljs-link,.hljs-operator,.hljs-regexp,.hljs-selector-attr,.hljs-selector-pseudo,.hljs-symbol,.hljs-template-variable,.hljs-variable{color:#ab5656}.hljs-literal{color:#695}.hljs-addition,.hljs-built_in,.hljs-bullet,.hljs-code{color:#397300}.hljs-meta{color:#1f7199}.hljs-meta .hljs-string{color:#38a}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}
*/

pre code.hljs {
display: block;
overflow-x: auto;
padding: 1em
}

code.hljs {
padding: 3px 5px
}

.hljs {
background: #f3f3f3;
color: #444
}

.hljs-comment {
color: #697070
}

.hljs-punctuation, .hljs-tag {
color: #444a
}

.hljs-tag .hljs-attr, .hljs-tag .hljs-name {
color: #444
}

.hljs-attribute, .hljs-doctag, .hljs-keyword, .hljs-meta .hljs-keyword, .hljs-name, .hljs-selector-tag {
font-weight: 700
}

.hljs-deletion, .hljs-number, .hljs-quote, .hljs-selector-class, .hljs-selector-id, .hljs-string, .hljs-template-tag, .hljs-type {
color: #800
}

.hljs-section, .hljs-title {
color: #800;
font-weight: 700
}

.hljs-link, .hljs-operator, .hljs-regexp, .hljs-selector-attr, .hljs-selector-pseudo, .hljs-symbol, .hljs-template-variable, .hljs-variable {
color: #ab5656
}

.hljs-literal {
color: #695
}

.hljs-addition, .hljs-built_in, .hljs-bullet, .hljs-code {
color: #397300
}

.hljs-meta {
color: #1f7199
}

.hljs-meta .hljs-string {
color: #38a
}

.hljs-emphasis {
font-style: italic
}

.hljs-strong {
font-weight: 700
}
57 changes: 51 additions & 6 deletions src/web/ownership.html
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ <h4>Non nullable members initialization</h4>

<p><button onclick="Try(this)">try</button></p>

<p>In some cases it may be useful to make the non-nullable members as nullable. Applying <code>_Opt</code> qualifier to structs makes all members nullable.</p>
<p>In some cases it may be useful to make the non-nullable members as nullable.
Applying <code>_Opt</code> qualifier to structs makes all members nullable.</p>

<p>For instance, the previous calloc sample can be written as.</p>

Expand All @@ -363,11 +364,57 @@ <h4>Non nullable members initialization</h4>

<p><button onclick="Try(this)">try</button></p>

<p>Adding the <code>_Opt</code> qualifier in front of <code>struct X</code> (as in <code>_Opt struct X x;</code>) is analogous to
changing the type of <code>x</code> from:</p>

<pre><code class="language-c">struct X { char * text; };
</code></pre>

<p>to:</p>

<pre><code class="language-c">struct X { char * _Opt text; };
</code></pre>

<p>This can be compared to the addition of the <code>const</code> qualifier.
For example:</p>

<pre><code class="language-c">const struct X x;
</code></pre>

<p>The type of <code>x</code> in this case is similar of to changing from:</p>

<pre><code class="language-c">struct X { char * text; };
</code></pre>

<p>to:</p>

<pre><code class="language-c">struct X { char * const text; };
</code></pre>

<p>We will discuss later another situation involving the <code>_View</code> qualifier that works as anti-owner qualifier.</p>

<h4>mutable</h4>

<p>In the same way we removed the implicit non-nullable qualifier, we also could remove the const qualifier. The anti const qualifier could be named as <code>mutable</code>.</p>
<p>In the same way we removed the implicit non-nullable qualifier, we also could remove the const qualifier.
The anti const qualifier could be named as <code>mutable</code>.</p>

<p>For instance:</p>

<pre><code class="language-c">struct X { char * const text; };
</code></pre>

<p>The declaration</p>

<pre><code class="language-c">mutable struct X x;
</code></pre>

<p>But instead of having anti-const and anti-non-nullable qualifier the mutable has been considered to remove both.</p>
<p>could be similar of having the type of <code>x</code> as:</p>

<pre><code class="language-c">struct X { char * text; };
</code></pre>

<p>But instead of having anti-const and anti-non-nullable qualifier the mutable has been
considered to remove both because they may happen together.</p>

<p>Consider the following code example:</p>

Expand All @@ -391,11 +438,9 @@ <h4>mutable</h4>
</code></pre>

<blockquote>
<p>OBS: mutable qualifier is not yet implemented. </p>
<p>OBS: mutable qualifier is not yet implemented in Cake. </p>
</blockquote>

<p>Note: The syntax used in the C++ 26 proposal for contracts may be utilized in the future to eliminate the need for built-in semantics for <code>malloc</code> and <code>calloc</code>.</p>

<h3 id="toc_3">Object lifetime checks</h3>

<p>From the C23 standard:</p>
Expand Down
5 changes: 2 additions & 3 deletions src/web/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ pre {
margin-top: 2px;
}

code {
vertical-align: text-top;
}


body {
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";
Expand All @@ -25,6 +23,7 @@ p {
}

code {
background-color: #f3f3f3;
font-family: Consolas
}

Expand Down

0 comments on commit 30cea19

Please sign in to comment.