Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
thradams committed Apr 22, 2024
1 parent 09ca439 commit 4e1b7e7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 89 deletions.
46 changes: 0 additions & 46 deletions ownership.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,52 +166,6 @@ constructed in case of some error.
For other functions, like use_x, the object must be completely constructed, and in this case, name must not be null.
Currently cake is not checkin nullable at initialization.
```c
struct X x = {0}; //no complaing about name being null
```

This allows a initialization in multiple steps.

```c
use_x(&x); //warning name is null
```
```c
#pragma nullable enable
void free(void * _Opt p);
char * _Opt strdup();
void print_name(const char* name);
struct X {
char * name;
};
void use_x(struct X * p)
{
//p->name is non-nullable here
print_name(p->name);
}
void x_destroy(_Opt struct X * p)
{
//p->name is nullable here
free(p); //free accepts nullable p
}
int main()
{
struct X x = {0};
use_x(&x);
x_destroy(&x);
}
```

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

### Owner References
An **owner reference** is an object referencing another object and managing its lifetime.
Expand Down
43 changes: 0 additions & 43 deletions src/web/ownership.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,49 +233,6 @@ <h4>pragma nullable disabled</h4>
constructed in case of some error.
For other functions, like use_x, the object must be completely constructed, and in this case, name must not be null.</p>

<p>Currently cake is not checkin nullable at initialization. </p>

<pre><code class="language-c">struct X x = {0}; //no complaing about name being null
</code></pre>

<p>This allows a initialization in multiple steps.</p>

<pre><code class="language-c"> use_x(&amp;x); //warning name is null
</code></pre>

<pre><code class="language-c">#pragma nullable enable

void free(void * _Opt p);
char * _Opt strdup();

void print_name(const char* name);

struct X {
char * name;
};

void use_x(struct X * p)
{
//p-&gt;name is non-nullable here
print_name(p-&gt;name);
}

void x_destroy(_Opt struct X * p)
{
//p-&gt;name is nullable here
free(p); //free accepts nullable p
}

int main()
{
struct X x = {0};
use_x(&amp;x);
x_destroy(&amp;x);
}
</code></pre>

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

<h3 id="toc_3">Owner References</h3>

<p>An <strong>owner reference</strong> is an object referencing another object and managing its lifetime. </p>
Expand Down

0 comments on commit 4e1b7e7

Please sign in to comment.