Skip to main content
11 events
when toggle format what by license comment
Nov 13, 2014 at 9:19 comment added pjc50 Have a look at "GLib data types": developer.gimp.org/api/2.0/glib which do the kind of things you'd use the STL data structures for. Requires slightly more manual memory management and isn't typesafe, but works fine.
Nov 13, 2014 at 3:00 comment added Michael Hampton Yes, we did a lot of this in C. Might still do, though I haven't seriously looked at any C in a very long time.
Nov 13, 2014 at 0:26 comment added Zan Lynx @IdeaHat: For generic functions look at qsort in the C library. It can sort anything because it takes a function pointer for the comparison function and passes a pair of void*'s.
Nov 12, 2014 at 17:29 comment added user22815 You could know the data type at the other end of the pointer by storing somewhere... perhaps in a table? Maybe a... vtable? This is the sort of stuff the compiler abstracts away for us. In other words, before compilers handled templates and polymorphism, we had to make our own.
Nov 12, 2014 at 16:57 vote accept IdeaHat
Nov 14, 2014 at 14:38
Nov 12, 2014 at 16:54 comment added Blrfl @IdeaHat: Yes, it would. But all of this comes from a time when there was much less emphasis on having the tools save the programmer from his own mistakes. In other words, you had to be careful because the language gave you a lot more rope to shoot yourself in the foot.
Nov 12, 2014 at 16:51 comment added user53141 I remember another pattern, which was to create a Object class and demand everything stored derive from that. Unfortunately, my brain is not coming up with concrete examples. It certainly wasn't as popular as void *. Also, I worked with at least one system that used an enum, stored along with the void *, to save type info.
Nov 12, 2014 at 16:35 comment added IdeaHat @Panzercrisis not storing function addresses. Replacing something like calling a operator class, template <typename T> int some_func(const T& t) { return t();}. A macro can do this (albeit without type checking).
Nov 12, 2014 at 16:32 comment added Panzercrisis @MadScienceDreams Why couldn't you apply this to function addresses?
Nov 12, 2014 at 16:28 comment added IdeaHat That works for generic storage, but what about generic functions? @gnat's macros can handle that, but this horrid little class can't. Won't this also lead to a nightmare of strict aliasing problems while processing the data?
Nov 12, 2014 at 16:21 history answered Robert Harvey CC BY-SA 3.0