 <p>The easiest way is to try to red it, and catch the exception.</p> <p>Catching the exception is done by defining an entry in the <code>__ex_table</code> secion, using inline assembly.<br> The exception table entry contains a pointer to a memory access instruction, and a pointer to a recovery address. If an segfault happens on this instruction, EIP will be set to the recovery address.</p> <p>Something like this (I didn't test this, I may be missing something):</p> <pre><code>void *ptr=whatever; int ok=1; asm( "1: mov (%1),%1\n" // Try to access "jmp 3f\n" // Success - skip error handling "2: mov $0,%0\n" // Error - set ok=0 "3:\n" // Jump here on success "\n.section __ex_table,\"a\"" ".long 1b,2b\n" // Use .quad for 64bit. ".prev\n" :"=r"(ok) : "r"(ptr) ); </code></pre>