logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Description

       A pointer to any object type may be converted to a pointer to void and back.  POSIX further requires that
       any pointer, including pointers to functions, may be converted to a pointer to void and back.

       Conversions  from  and  to  any other pointer type are done implicitly, not requiring casts at all.  Note
       that this feature prevents any kind of type checking: the programmer should be careful not to  convert  a
       void*  value  to  a  type  incompatible  to  that  of the underlying data, because that would result in
       undefined behavior.

       This type is useful in function parameters and return value to allow passing values  of  any  type.   The
       function  will  typically use some mechanism to know the real type of the data being passed via a pointer
       to void.

       A value of this type can't be dereferenced, as it would give a value of type void, which is not possible.
       Likewise, pointer arithmetic is not possible with this type.  However, in GNU C,  pointer  arithmetic  is
       allowed  as an extension to the standard; this is done by treating the size of a void or of a function as
       1.  A consequence of this is that sizeof is also allowed on void and on function types, and returns 1.

   Usewithprintf(3)andscanf(3)
       The conversion specifier for void* for the printf(3) and the scanf(3) families of functions is p.

History

       C89, POSIX.1-2001.

Name

       void - abstract type

See Also

malloc(3), memcmp(3), memcpy(3), memset(3), intptr_t(3type)

Linux man-pages 6.9.1                              2024-05-02                                        void(3type)

Standards

       C11, POSIX.1-2008.

Synopsis

void*

Versions

       The POSIX requirement about compatibility between void* and function pointers was added in  POSIX.1-2008
       Technical Corrigendum 1 (2013).

See Also