Re: gcc warnings

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

 



Hi Jiri,

It's valid C code to assign from a variable of greater type to one of
smaller type.

I think that this is very unfortunate.  I presume you do as well.  Alas.

You can act upon it programmatically, in runtime, if you do something like:

#include "stdio.h"

unsigned char LongAsUnsignedChar(long c)
{
  if(c > 255 || c < 0)
  {
    fprintf(stderr, "Error: %ld outside of 0,255 range\n", c);
  }

  return c;
}

int main()
{
  long a = 10000;
  unsigned char b = LongAsUnsignedChar(a);

  printf("%d\n", b);

  return b;
}

Alternatively, you can use a B&D language like Ada where such assignments
cannot happen silently and need explicit conversion.

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