Skip to content

Commit 9ed3516

Browse files
committed
docs and warning removal
1 parent 4c61124 commit 9ed3516

File tree

18 files changed

+285
-263
lines changed

18 files changed

+285
-263
lines changed

ownership.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11

22
Last Updated 5 December 2025
33

4-
This is a work in progress. Cake source is currently being used to validate the concepts.
4+
## Cake Static Analysis
55

6-
7-
## Abstract
86

9-
The objective is to statically check code and prevent bugs, including memory bugs like double free,
10-
null dereference and memory leaks.
11-
12-
Type-annotations have been created to extend the type system and insert information that defines contracts.
7+
Cake provides a set of annotations and extended qualifiers that are recognized by
8+
the static analyzer.
9+
With ownership qualifiers, it is possible to achieve the same or even stronger guarantees
10+
than those provided by C++ RAII. It also introduces the concept of nullable pointers,
11+
which helps express when a pointer may be null and prevents mistakes such as
12+
accidentally dereferencing a null pointer.
1313

14-
These new type-annotations can be ignored, the language **and existing code patterns** remains unmodified.
1514

1615
## Concepts
1716

@@ -838,6 +837,8 @@ int main() {
838837

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

840+
Obs: [[ctor]] in cake is similar of \_Out in Microsoft SAL
841+
841842

842843
**Sample - Using `x_destroy` to implement `x_delete`**
843844

@@ -856,7 +857,7 @@ void x_destroy( [[dtor]] struct X * x) {
856857

857858
void x_delete(_Opt struct X * _Owner _Opt p) {
858859
if (p) {
859-
x_destroy(p)
860+
x_destroy(p);
860861

861862
/*
862863
contents of *p where moved
@@ -1395,7 +1396,7 @@ void list_append(struct list* list, struct node* _Owner node)
13951396
<button onclick="Try(this)">try</button>
13961397
13971398
1398-
## Cake's static analysis limitations
1399+
## Limitations
13991400
14001401
While Cake tracks possible states, such as maybe-null, it does not track
14011402
the origin or relationships between these states.
@@ -1450,7 +1451,12 @@ A header `safe.h` can define all cake extensions as empty macros.
14501451
14511452
## References
14521453
1453-
[1] https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references, https://learn.microsoft.com/en-us/dotnet/csharp/nullable-migration-strategies?source=recommendations
1454+
[1] https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references,
14541455
1456+
https://learn.microsoft.com/en-us/dotnet/csharp/nullable-migration-strategies?source=recommendations
14551457
14561458
https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates
1459+
1460+
Microsoft SAL
1461+
https://learn.microsoft.com/en-us/cpp/code-quality/understanding-sal?view=msvc-170
1462+

src/build.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static void generate_doc(const char* mdfilename, const char* outfile)
8282
"</head>\n"
8383
"<body>\n"
8484
" <article style=\"max-width: 40em; margin:auto\">\n"
85-
"<p><a href=\"index.html\">Home</a> | <a href=\"manual.html\">Manual</a> | <a href=\"ownership.html\">Ownership</a> | <a href=\"playground.html\">Playground</a></p>\n"
85+
"<p><a href=\"index.html\">Home</a> | <a href=\"manual.html\">Manual</a> | <a href=\"ownership.html\">Static Analysis</a> | <a href=\"playground.html\">Playground</a></p>\n"
8686
"<article>\n"
8787
"<h1>Cake - C23 and Beyond</h1>\n";
8888

src/expressions.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ struct expression* _Owner _Opt primary_expression(struct parser_ctx* ctx, enum e
15681568
the braces, the construct has type void, and thus effectively no value.)
15691569
*/
15701570
struct expression* _Opt p_last_expression = NULL;
1571-
struct block_item* _Owner _Opt p = p_expression_node->compound_statement->block_item_list.head;
1571+
struct block_item* _Opt p = p_expression_node->compound_statement->block_item_list.head;
15721572
while (p)
15731573
{
15741574
if (p->next == NULL &&
@@ -3271,7 +3271,7 @@ struct expression* _Owner _Opt unary_expression(struct parser_ctx* ctx, enum exp
32713271
size_t nelements = 0;
32723272
if (p_enum_specifier)
32733273
{
3274-
struct enumerator* _Owner _Opt p =
3274+
struct enumerator* _Opt p =
32753275
p_enum_specifier->enumerator_list.head;
32763276
while (p)
32773277
{
@@ -3339,7 +3339,7 @@ struct expression* _Owner _Opt unary_expression(struct parser_ctx* ctx, enum exp
33393339
size_t nelements = 0;
33403340
if (p_enum_specifier)
33413341
{
3342-
struct enumerator* _Owner _Opt p =
3342+
struct enumerator* _Opt p =
33433343
p_enum_specifier->enumerator_list.head;
33443344
while (p)
33453345
{

src/file.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
int main(int argc, char *argv[]) {
2-
while (1) {
3-
if (argc) {
4-
goto one;
5-
}
6-
else {
7-
goto zero;
8-
}
9-
zero:
10-
return 0;
11-
one:
12-
return 1;
13-
}
1+
#include <ctype.h>
2+
3+
int main(void)
4+
{
5+
unsigned char c = '\xdf'; // German letter ß in ISO-8859-1
6+
7+
isalnum(c);
8+
149
}

src/include/stdio.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ extern FILE* stdout;
3636
extern FILE* stderr;
3737

3838
typedef unsigned long size_t;
39-
typedef void* va_list;
39+
typedef char* va_list;
40+
4041
int remove(const char* filename);
4142
int rename(const char* old, const char* news);
4243
FILE* _Opt tmpfile(void);

0 commit comments

Comments
 (0)