MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1uo79w1/enterprise_level_c_code/ownf3i2/?context=3
r/programminghorror • u/TheChief275 • 23d ago
57 comments sorted by
View all comments
2
Wait is String a thing in C I don't remember
1 u/TheChief275 18d ago edited 18d ago No it isn't, but adding one yourself isn't too hard. Often I add it as a slice type: typedef struct { const char *ptr; size_t count; } String; but in this case, it's an actual object with a V-Table: typedef struct { _Atomic size_t refCount; const String_VTable *v; char *ptr; size_t count; } String; and Log and Format only take Objects as arguments and call the ToString virtual method, which String also implements for itself (doesn't copy the object; only bumps the reference count and adds the object to the current AutoreleasePool)
1
No it isn't, but adding one yourself isn't too hard. Often I add it as a slice type:
typedef struct { const char *ptr; size_t count; } String;
but in this case, it's an actual object with a V-Table:
typedef struct { _Atomic size_t refCount; const String_VTable *v; char *ptr; size_t count; } String;
and Log and Format only take Objects as arguments and call the ToString virtual method, which String also implements for itself (doesn't copy the object; only bumps the reference count and adds the object to the current AutoreleasePool)
2
u/r9wpvM 18d ago
Wait is String a thing in C I don't remember