summaryrefslogtreecommitdiffhomepage
path: root/advanced_example.md
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-04-26 23:41:47 +0200
committerGitHub <[email protected]>2020-04-26 23:41:47 +0200
commit846347b4dc70c599fb16c2e01b163f15602aaa09 (patch)
treed53fdfa752a50d1831fb39519d1b60f4d6280166 /advanced_example.md
parent749ec1f9265ea3c02084a876c5f7c9651242c9f8 (diff)
downloadSTC-modified-846347b4dc70c599fb16c2e01b163f15602aaa09.tar.gz
STC-modified-846347b4dc70c599fb16c2e01b163f15602aaa09.zip
Update advanced_example.md
Diffstat (limited to 'advanced_example.md')
-rw-r--r--advanced_example.md5
1 files changed, 4 insertions, 1 deletions
diff --git a/advanced_example.md b/advanced_example.md
index 7771b3c9..ff93c4c9 100644
--- a/advanced_example.md
+++ b/advanced_example.md
@@ -35,17 +35,20 @@ struct PersonView {
const char* surname;
int age;
};
+
struct PersonView person_getView(struct Person* p) {
return (struct PersonView) {p->name.str, p->surname.str, p->age};
}
+
struct Person person_fromView(struct PersonView pv) {
return (struct Person) {cstring_make(pv.name), cstring_make(pv.surname), pv.age};
}
+
int personview_compare(const struct PersonView* x, const struct PersonView* y) {
int c;
c = strcmp(x->name, y->name); if (c != 0) return c;
c = strcmp(x->surname, y->surname); if (c != 0) return c;
- return memcmp(&x->age, &y->age, sizeof(x->age));
+ return x->age - y->age;
}
```
And a hash function that combines the three member's hashes: