-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
88,722 additions
and
86,257 deletions.
There are no files selected for viewing
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,15 @@ | ||
# Learning Cake owership by samples | ||
|
||
Learning Cake owernship by samples is an effective way to grasp the ownership concepts and syntax | ||
through practical examples. | ||
|
||
|
||
```c | ||
#include <stdio.h> | ||
int main() | ||
{ | ||
void * p = malloc(1); | ||
} | ||
``` | ||
|
||
|
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 |
---|---|---|
@@ -1,38 +1,29 @@ | ||
|
||
void* _Owner malloc(unsigned long size); | ||
void free(void* _Owner ptr); | ||
|
||
struct Y { | ||
char* _Owner p0; | ||
int* _Owner p2; | ||
double i2; | ||
//en.cppreference.com/w/c/language/_Alignas.html | ||
#include <stdalign.h> | ||
#include <stdio.h> | ||
|
||
// every object of type struct sse_t will be aligned to 16-byte boundary | ||
// (note: needs support for DR 444) | ||
struct sse_t | ||
{ | ||
alignas(16) float sse_data[4]; | ||
}; | ||
|
||
struct X { | ||
char* _Owner text; | ||
int* _Owner p1; | ||
int i; | ||
struct Y* pY; | ||
|
||
// every object of type struct data will be aligned to 128-byte boundary | ||
struct data | ||
{ | ||
char x; | ||
alignas(128) char cacheline[128]; // over-aligned array of char, | ||
// not array of over-aligned chars | ||
}; | ||
|
||
void init(struct X* p); | ||
|
||
int main() { | ||
struct X x; | ||
/*lying here, to avoid error of using uninitialized*/ | ||
static_set(x, "zero"); | ||
init(&x); | ||
|
||
static_state(x.p1, "maybe-null"); | ||
static_state(x.i, "any"); | ||
static_state(x.pY, "maybe-null"); | ||
static_state(x.pY->p0, "maybe-null"); | ||
static_state(x.pY->p2, "maybe-null"); | ||
static_state(x.pY->i2, "any"); | ||
free(x); | ||
} | ||
|
||
|
||
void dummy() {} | ||
|
||
#pragma cake diagnostic check "-Wmaybe-uninitialized" | ||
|
||
int main(void) | ||
{ | ||
printf("sizeof(data) = %zu (1 byte + 127 bytes padding + 128-byte array)\n", | ||
sizeof(struct data)); | ||
|
||
printf("alignment of sse_t is %zu\n", alignof(struct sse_t)); | ||
|
||
alignas(2048) struct data d; // this instance of data is aligned even stricter | ||
(void)d; // suppresses "maybe unused" warning | ||
} |
Oops, something went wrong.