Re: C++: No Warning for passing value > 255 as parameter to a function requiring "unsigned char"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Martin,

Change this...

unsigned char var = 1000;

...to this...

unsigned char var = MakeUnsignedChar(1000);

And add the function:

#include <stdio.h>
#include <stdlib.h>
unsigned char MakeUnsignedCharFromInt(int x)
{
  if(x > 255 || x < 0)
  {
      fprintf(stderr, "Parameter %d out of unsigned char bounds.", x);
      abort();
  }
  return (unsigned char)x;
}

HTH,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux