News for hackers. Stuff that matters.
Re:Announcing TypeScript 0.9.1 by harrytuttle on Wednesday August 07, 2013 @07:29AM (#6172051)
void* is used rarely in practice, apart from perhaps kernel mode or language VM's. I have a 150kloc program in front of me which doesn't have a single void*.
Re:Announcing TypeScript 0.9.1 by michaelwww on Wednesday August 07, 2013 @07:42AM (#6172112)
Great. That makes more sense. I must have misunderstood what you were saying.
Re:Announcing TypeScript 0.9.1 by harrytuttle on Wednesday August 07, 2013 @09:05AM (#6172500)
Yes we're not gluttons for punishment believe me :)
Re:Announcing TypeScript 0.9.1 by nly on Wednesday August 07, 2013 @08:23AM (#6172275)
void* is used in practically every C library that offers a callback facility.
Re:Announcing TypeScript 0.9.1 by harrytuttle on Wednesday August 07, 2013 @09:04AM (#6172496)
Almost...

You have a typed pointer to a function but that's not a void pointer and the "New C Standard" 6.3.2.3 states that you can't cast a function pointer to a void*.

Re:Announcing TypeScript 0.9.1 by ygra on Wednesday August 07, 2013 @09:21AM (#6172595)
Not for function pointers; for passing data to callbacks that can be any type.
Re:Announcing TypeScript 0.9.1 by harrytuttle on Wednesday August 07, 2013 @09:23AM (#6172614)
Can you provide an example? Not 100% sure in which context you are talking about.
Re:Announcing TypeScript 0.9.1 by ygra on Wednesday August 07, 2013 @09:54AM (#6172801)
As an example, SQLite:

    int sqlite3_exec(
      sqlite3*,                                  /* An open database */
      const char *sql,                           /* SQL to be evaluated */
      int (*callback)(void*,int,char**,char**),  /* Callback function */
      void *,                                    /* 1st argument to callback */
      char **errmsg                              /* Error msg written here */
    );
Here the void * is an argument that is passed in the callback as well so that you can update your own struct with the result, for example. Singe the library cannot know anything about your types, void * is the only option.
Re:Announcing TypeScript 0.9.1 by harrytuttle on Wednesday August 07, 2013 @11:52AM (#6173599)
Thanks for the example. Agree entirely then :)