{"id":13838117,"url":"https://github.com/milgra/headerlessc","last_synced_at":"2025-07-10T21:31:20.349Z","repository":{"id":66748984,"uuid":"137052390","full_name":"milgra/headerlessc","owner":"milgra","description":"Headerless C programming with a single preprocessor macro line","archived":false,"fork":false,"pushed_at":"2022-12-24T07:41:15.000Z","size":15,"stargazers_count":51,"open_issues_count":1,"forks_count":3,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-21T01:34:39.696Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/milgra.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}},"created_at":"2018-06-12T09:56:58.000Z","updated_at":"2024-05-17T19:20:37.000Z","dependencies_parsed_at":"2023-07-30T21:15:09.831Z","dependency_job_id":null,"html_url":"https://github.com/milgra/headerlessc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/milgra/headerlessc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milgra%2Fheaderlessc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milgra%2Fheaderlessc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milgra%2Fheaderlessc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milgra%2Fheaderlessc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/milgra","download_url":"https://codeload.github.com/milgra/headerlessc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milgra%2Fheaderlessc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264666021,"owners_count":23646570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-08-04T15:01:37.997Z","updated_at":"2025-07-10T21:31:20.107Z","avatar_url":"https://github.com/milgra.png","language":null,"funding_links":[],"categories":["Others"],"sub_categories":[],"readme":"\n# Headerless C programming with a single macro definition\n\n Header files in C are painful. They duplicate file count, increase complexity, make refactoring painful. There are solutions to get rid of them. It's possible to use header generators ( https://www.hwaci.com/sw/mkhdr/ - makeheaders ), write you own headerless c dialect with a precompiler like me ( https://github.com/milgra/clc class-c ) or use `\"#ifdef FOO_IMPLEMENTATION\"` blocks inside header files to define everything in one file but they are unelegant and confusing and have a lot of other problems.\n\nThe ultimate solution seems to be using the `__INCLUDE_LEVEL__` preprocessor macro. It's value is zero if we are in a source file that was added directly to the compiler as parameter and greater than zero if we are in a file that was included as a header file from an other file.\n\nSo just create a single file, write the header declarations at the top, write the implementation under that and guard the implementation with an `#if __INCLUDE_LEVEL__ == 0` macro and you never have to use header files again unless you need a library interface. You can include all files written this way as header files and add these files as source files to the compiler, everything will work as before.\n\nExample : mtvec.c\n```\n#ifndef mtvec_h\n#define mtvec_h\n\n#include \u003cstdio.h\u003e\n#include \u003cstdint.h\u003e\n\ntypedef struct mtvec_t mtvec_t;\n\nstruct mtvec_t\n{\n    void** data;\n    uint32_t length;\n    uint32_t length_real;\n};\n\nmtvec_t* mtvec_alloc(void);\nvoid mtvec_dealloc( void* vector );\nvoid mtvec_reset( mtvec_t* vector );\n\n#endif\n\n#if __INCLUDE_LEVEL__ == 0\n\nmtvec_t* mtvec_alloc( )\n{\n    mtvec_t* vector = mtmem_calloc( sizeof( mtvec_t ) , mtvec_dealloc );\n    vector-\u003edata = mtmem_calloc( sizeof( void* ) * 10 , NULL );\n    vector-\u003elength = 0;\n    vector-\u003elength_real = 10;\n    return vector;\n}\n\nvoid mtvec_dealloc( void* pointer )\n{\n    mtvec_t* vector = pointer;\n\n    for ( uint32_t index = 0 ; index \u003c vector-\u003elength ; index++ ) {\n    mtmem_release( vector-\u003edata[index] );\n    }\n    mtmem_release( vector-\u003edata );\n}\n\nvoid mtvec_reset( mtvec_t* vector )\n{\n    for ( uint32_t index = 0 ; index \u003c vector-\u003elength ; index++ ) mtmem_release( vector-\u003edata[index] );\n\n    vector-\u003elength = 0;\n}\n\n#endif\n```\n\nI created/maintain seven applications so far in headerless C and haven't faced any drawbacks yet, feel free to try them :\n\n- MultiMedia File Manager (https://github.com/milgra/mmfm)  \n- Visual Music Player (https://github.com/milgra/vmp)  \n- Wayland Control Panel (https://github.com/milgra/wcp)  \n- Sway Overview (https://github.com/milgra/sov)  \n- Cortex (https://github.com/milgra/cortex)  \n- Termite (https://github.com/milgra/termite)  \n- Brawl (https://github.com/milgra/brawl)  \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilgra%2Fheaderlessc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilgra%2Fheaderlessc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilgra%2Fheaderlessc/lists"}