![]() Except that there is some redundancy in what code I must generate from macros to make it work. And it did I have a solution I am reasonably satisfied with. So, I figured macros would get me most of the way, with _Generic() expressions for static type dispatch. C doesn’t do generic types, and there are a couple of places where you need to provide type information. Nothing in the source code really changes, just the type information. ![]() That varies, and thus so does the return type of indexing, some initialisation code (where the user provides the buffer that must be of the correct type) and a few other things. They all behave exactly the same, even with the same code, except for the type of the underlying buffer. The only thing that makes it difficult is that I need slices of different types. You need a pointer to an underlying buffer and a length (and maybe a capacity), and that’s that. There is nothing complicated in implementing such slices. ![]() Essentially arrays, but where I can index from the end using negative numbers (like in Python) and where I can extract a sub-slice, x, in constant time (like in Go I implement them the same way as Go does). I’ve been working on a small C library for Python- or Go-like slices the last couple of weeks. On Writing, Science, Programming and more
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |