title: is it correct to cast an integer to enumerated type?
body: <p>My research has not yielded an answer for this yet (in SOF), but I am sure it must have been asked somewhere before, appologies if so.</p>
  
  <p>I have created an enumerated type in c++ and then I read in a value from a message header and want to store it into a variable of my enum type, example:</p>
  
  <pre><code>// My defined enum type
  enum myNumType_t
  {
      MY_NUM_UNKNOWN = 0,
      MY_NUM1 = 1,
      MY_NUM2 = 2,
      MY_NUM3 = 3,
      MY_NUM4 = 4,
      MY_NUM5 = 5,
  };
  
  // In the code
  int main()
  {
      myNum_t myNum = MY_NUM_UNKNOWN;
      myNum = getMessageNumType(); // returns an int
  
      return 0;
  }
  </code></pre>
  
  <p>So, this code does not compile in c++ because it can't convert the int to myNum_t, fair enough. So then if I cast it <code>myNum = (myNum_t) getMessageNumType();</code> this of course now compiles. But does it do the right thing? What happens if the returned value is out of range of myNum_t? Is there a "best practise" here that I am missing?</p>