This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Type promotion bug?

Specific pointer -> generic pointer -> boolean (i.e. implicit compare to 0) seems not to work as expected.

void main()
{
  char* p;
  char* q;
  char xdata* xp = NULL;

  bit fail = FALSE;

  // This fails.
  if ( p = xp )
  {
    fail = TRUE;
  }

  // This is ok.
  if ( ( q = xp ) == NULL )
  {
    fail = TRUE;
  }
}

Parents
  • My point is that it's probably OK to break standard conformance in some places if it's justified by performance/simplicity/etc considerations. After all, if one wants standard C behaviour, they can limit themselves to using generic pointers only.

    I guess that this is the nub of the matter. If you write standard C code, you will always be getting generic pointers and, hence, standard C behaviour. Memory specific keywords are Keil extensions and if you choose to use them it is necessary to understand how they work in some detail.

Reply
  • My point is that it's probably OK to break standard conformance in some places if it's justified by performance/simplicity/etc considerations. After all, if one wants standard C behaviour, they can limit themselves to using generic pointers only.

    I guess that this is the nub of the matter. If you write standard C code, you will always be getting generic pointers and, hence, standard C behaviour. Memory specific keywords are Keil extensions and if you choose to use them it is necessary to understand how they work in some detail.

Children
No data