cglibclibc

glibc - #define void


I started to look into glibc (GNU Libc) to understand how it's written. In malloc.c, I found a piece of code as follow:

#ifndef void
#define void        void
#endif

Can someone please explain to me what this means? Isn't void always defined?

Thanks


Solution

  • Looking at the git history, it was like this:

    /*
      Void_t* is the pointer type that malloc should say it returns
    */
    
    #ifndef Void_t
    #if (__STD_C || defined(WIN32))
    #define Void_t      void
    #else
    #define Void_t      char
    #endif
    #endif /*Void_t*/
    

    This was a workaround for historical [C], which did not have void and malloc() returned char * instead of void. The code was removed by Ulrich Drepper in 2011. The commit does not seems to be generated by a script or anything automatic, so he must had some intention to define it like that.

    The commit message does not say anything about void:

    Simplify malloc code

    Remove all kinds of unused configuration options and dead code.