Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Type agnosticism, data structures and C

Name: Anonymous 2011-09-16 6:07

/prog/, I've been working on a C library with basic data structures and useful functions, and have implemented things like doubly-linked lists and vectors and so on. Now I'm working on Unicode-based string support. Here's my issue.

I've implemented type agnosticism on the vector type using void pointers (not preprocessor macros), so I want to use the vector type to represent a string. Each Unicode codepoint is an int32_t. Of course, I don't want to have to allocate four bytes on the heap for each codepoint, then point to that from each vector element; that's utterly stupid. On the other hand, doing typecasts to shove an integer in the void * type is kludgy and works very poorly, often requiring double explicit casts; once to expand/shrink the type's size, then once more to explicitly cast to a pointer or back.

How can I solve my issues and use my vector type for strings?

Name: Anonymous 2011-09-16 6:52

>>13
I did call my solution the best, not me.

Also, preprocessor macros are for faggots.
No, they aren't. That's what Bjarne Stroustrup wants you to believe.

If you absolutely want to avoid reader typecasting, the only solutions I see are:
- Switch to C++ and use templates;
- Implement dynamic typing, which will be slow as fuck;
- Use kludges such as the one you described in >>1.
Perhaps a better programmer will find others.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List