title: How to check whether an int variable contains a legal (not trap representation) value?
body: <h3>Context:</h3>
  
  <p>This is mainly a followup to <a href="https://stackoverflow.com/q/59615243/3545273">that other question</a>. OP wanted to guess whether a variable contained an int or not, and my first thought was that in C (as in C++) an int variable could only contain an int value. And Eric Postpischil reminded me that <em>trap representations</em> were allowed per standard for the int type...</p>
  
  <p>Of course, I know that most modern system only use 2-complement representations of integers and no padding bits, meaning that no trap representation can be observed. Nevertheless both standards seem to still allow for 3 representations of signed types: sign and magnitude, one's complement and two's complement. And at least C18 draft (n2310 6.2.6 Representations of types) explicitely allows padding bits for integer types other that char.</p>
  
  <h3>Question</h3>
  
  <p>So in the context of possible padding bits, or non two's complement signed representation, <code>int</code> variables could contain trap values for conformant implementations. Is there a reliable way to make sure that an int variable contains a valid value?</p>