Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>const void</code> is allowed simply because there is no point making the compiler kick out this one exception to a general rule and it does no harm to leave it in.</p> <p>There is some discussion above that <code>const void*</code> is not very useful:</p> <blockquote> <p>How useful is const void *? I can see how void * const could be, but not the former. –Spidey</p> </blockquote> <p>In fact <code>const void*</code> is sometimes essential. It declares that the thing being pointed to is read only as opposed to <code>void* const</code> which only declares that the pointer itself is constant but not the thing it points to.</p> <p>From my experience, the pointer to constant using <code>const void*</code> is the more useful of the two forms. Of course, there is also <code>const void* const</code> meaning that both the pointer and the thing it points to are constant.</p> <p><code>void*</code> is normally used as a way to pass non-specific pointers around (e.g. with <code>memcpy()</code>). If you want to pass a <code>const char*</code> to such a function then you cannot use <code>void*</code> or you lose the fact that the thing it points to is constant and cannot be altered. Current C++ compilers will refuse to compile that as it would have to implicitly cast the <code>const</code> away, and rightfully so as this data might be in read-only memory and possibly cause an exception if anything tries to write to it.</p> <p>This is why the second argument to <code>memcpy()</code> is <code>const void*</code> and not simply <code>void*</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload