wish C had generics
-
wish C had generics
-
lawless polymorphreplied to lawless polymorph last edited by
or absent a general solution ... wish C had a generic vector type.
-
raeaw (land back π΅πΈπ¦π²β¬π‘π₯)replied to lawless polymorph last edited by
@typeswitch inb4 some nerd says it's fine, just give up most of the language's type safety features by using macros
-
lawless polymorphreplied to lawless polymorph last edited by
but really i don't think it's a huge stretch to add some kind of type polymorphism to C ... the biggest question would be how to handle representation differences between types, and I think the simplest solution would be to treat generic types like an unknown/incomplete type. so generic code can't assume a size/alignment, but it can handle them using pointers, and/or use them as the last field in a struct.
-
lawless polymorphreplied to lawless polymorph last edited by
we can already emulate this by using "struct T" (for some struct type T that is never defined), with the unfortunate caveat that you have to convert pointers to struct T manually to/from the types you actually want, and there's no type safety. i want type safety.
-
Riley S. Faelanreplied to lawless polymorph last edited by
@typeswitch One thing that I really, really want is adding semantic data to integers.
If you can notate your integer to be a pointer to a particular array, to be implicitly checked against the array's size, and to be implicitly treated as a fetch or store operation when you dereference the pointer, you get a lot of safety automatically, and your code will be nicer to read, too.
I also want to have
each
for all the common container types. If you do this in conjunction with a mechanism to delineate arrays not just by external size but also by an in-band terminator, such as, I don't know,'\0'
, C-style NUL-terminated strings will suddenly look a lot safer than they used to. -
Riley S. Faelanreplied to raeaw (land back π΅πΈπ¦π²β¬π‘π₯) last edited by
@raeaw C macros are an ill wind.