Before confidently predicting the future of software programming languages, please consider the following. There are operating systems written in the C programming language. And those are:
Linux and Windows.
But wait! The foundations of Mac OS familly are also written in C. That means all 3 operating systems most used today. And all their derivatives, like Android. Or iOS. All written in the C programming language.
But why C?
Because C toolkits produce smallest and fastest software. Fully functional and resilient. And easy to maintain. Is that not the primary objective?
C keeps things on the path of the primary objective.
And, hardware interfaces are written in C, too. These include infrastructure, networks, avionics, electronics, satellites, and more.
Appendix
Below is a modern C, circa 2025. For you to peruse.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
/* https://godbolt.org/z/q5Gj54WMa (c) 2025 by dbj@dbj.org Arena memory layout: Arena: [string_t #1][string_t #2][string_t #3] | | | v v v External: buf[] "Hello World" "Partial String" Only the string_t metadata lives in the arena, the actual character data stays wherever it was */ #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> // string_t print #define SP(S_) \ fprintf(stdout, "\n%04d : %16s{ %4zu , \"%s\" }", __LINE__, #S_, \ ((S_).len), ((S_).ptr)) #define P(F, X_) fprintf(stdout, "\n%04d : %16s :\t" F, __LINE__, #X_, (X_)) #define SPP(S_) SP((*S_)) // #define dbj_string(s) (string_t) { .ptr = (char*)s, .len = sizeof(s) } typedef struct { char* ptr; size_t len; } string_t; typedef struct { char* buffer; size_t size; size_t used; } Arena; static Arena arena_create(size_t size) { Arena arena = {0}; arena.buffer = calloc(size, sizeof(char)); assert(arena.buffer); arena.size = size; arena.used = 0; return arena; } void* arena_alloc(Arena* arena, size_t size) { size_t aligned = (size + 7) & ~7; if (arena->used + aligned > arena->size) return NULL; void* ptr = arena->buffer + arena->used; arena->used += aligned; return ptr; } void arena_destroy(Arena* arena) { assert(arena); free(arena->buffer); *arena = (Arena){0}; } // Allocate only the string_t struct in arena, ptr points to external memory string_t string2arena(Arena* arena, string_t s) { string_t* str = arena_alloc(arena, sizeof(string_t)); assert(str); return *str = s; // Copy the struct (ptr still points outside arena) } // Allocate the string literal in arena #define literal2arena(arena_ptr, slit) \ string2arena(arena_ptr, \ (string_t){.ptr = (char*)slit, .len = sizeof(slit) - 1}) /*************************************************************************************/ // Iterator callback: return 0 to continue, non-zero to stop typedef int (*arena_visitor_fn)(string_t* str, void* userdata); void arena_walk(Arena* arena, arena_visitor_fn visit, void* userdata) { assert ( arena || visit) ; // Safety check char* pos = arena->buffer; char* end = arena->buffer + arena->used; while (pos < end) { string_t* str = (string_t*)pos; if (visit(str, userdata)) break; // Early exit if visitor returns non-zero pos += ((sizeof(string_t) + 7) & ~7); // Same alignment as arena_alloc } } // Example visitor: print the string arena_visitor_fn print_visitor(string_t* str, void* userdata) { SP(*str); // printf("{ len=%zu, ptr=\"%.*s\" }\n", str->len, (int)str->len, str->ptr); return 0; // Continue } // Example visistor: count strings int count_visitor(string_t* str, void * userdata) { (*(int*)userdata)++; return 0; } /*************************************************************************************/ int main(void) { Arena arena = arena_create(0xFFF); char buf[100] = "String on the static array"; string_t s1 = literal2arena(&arena, "Literal"); // literal to arena (literal2arena(&arena, "Literal in Arena")); // static chat array to arena (literal2arena(&arena, buf)); // string_t to arena (string2arena(&arena, s1)); P("%zu", arena.used); P("%zu", arena.size); arena_walk(&arena, print_visitor, NULL); int count = 0; arena_walk(&arena, count_visitor, &count); printf("\nTotal strings: %d\n", count); arena_destroy(&arena); return 0; } |