{"id":15991166,"url":"https://github.com/friendlyanon/generate-opaque-structs","last_synced_at":"2026-04-08T14:04:17.973Z","repository":{"id":68574210,"uuid":"453087280","full_name":"friendlyanon/generate-opaque-structs","owner":"friendlyanon","description":"Example to show how to generate opaque structs with proper size and alignment","archived":false,"fork":false,"pushed_at":"2022-01-29T04:22:06.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-25T06:54:25.446Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/friendlyanon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-28T13:57:46.000Z","updated_at":"2023-03-23T17:40:06.000Z","dependencies_parsed_at":"2023-02-24T04:45:45.344Z","dependency_job_id":null,"html_url":"https://github.com/friendlyanon/generate-opaque-structs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/friendlyanon/generate-opaque-structs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendlyanon%2Fgenerate-opaque-structs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendlyanon%2Fgenerate-opaque-structs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendlyanon%2Fgenerate-opaque-structs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendlyanon%2Fgenerate-opaque-structs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/friendlyanon","download_url":"https://codeload.github.com/friendlyanon/generate-opaque-structs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendlyanon%2Fgenerate-opaque-structs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31558389,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T10:21:54.569Z","status":"ssl_error","status_checked_at":"2026-04-08T10:21:38.171Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-08T05:42:28.128Z","updated_at":"2026-04-08T14:04:17.949Z","avatar_url":"https://github.com/friendlyanon.png","language":"CMake","funding_links":[],"categories":[],"sub_categories":[],"readme":"# generate-opaque-structs\n\nThis project was generated by [cmake-init][1].  \nIt's heavily stripped down to focus on showing how to create opaque structs\nthat preserve value semantics.\n\nThis project makes use of the [CheckTypeSize][2] and [CheckTypeAlign][3] CMake\nmodules to get the size and alignment of the implementation specific struct,\nand creates an opaque struct using those parameters.\n\nDoing this will allow the consumers of an API to not be forced to allocate\nthese structs on the heap, but instead put them on the stack like normal\nvalues. They will not be able to observe the struct's state, because all they\nwill see is a byte buffer in the struct exposed to them.\n\nNote that this project requires C11 to be able to use the `_Alignas` keyword,\nbut a developer crafty enough could make this work just as well with earlier\nstandards. I can only think of having a buffer of size `x_SIZE + 2 * x_ALIGN`\nand the user facing functions do some pointer arithmetic to snap the incoming\npointer to a valid alignment within that buffer before casting it to a pointer\nto the implementation. However, `(u)intptr_t` was added in C99 as an optional\nfeature, so that pointer arithmetic would be cumbersome and non-portable.\n\n[1]: https://github.com/friendlyanon/cmake-init\n[2]: https://cmake.org/cmake/help/latest/module/CheckTypeSize.html\n[3]: https://github.com/friendlyanon/check-type-align\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriendlyanon%2Fgenerate-opaque-structs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffriendlyanon%2Fgenerate-opaque-structs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriendlyanon%2Fgenerate-opaque-structs/lists"}