Re: Assign pointers of different objects to the same pointer

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

 



sebastian writes:
 > 
 > >  > (That's pointers get handled in other languages, without a standard for
 > >  > objective oriented programming)
 > >  > But a pointer can point to whatever you want
 > >
 > > No, it can't.  Not in C or C++ it can't.  A pointer can only point to
 > > a compatible type.  Anything else is undefined.
 > Surely not c and c++ but generally or in other languages and for the CPU (ptr) 
 > are all pointers the same.

I think you're missing something important.  

gcc and many other compilers will not do what you expect if you make a
pointer point to a type other than a compatible type.  Consider this
function:

int poo (int *a, short *p)
{
  *a = 99;
  *p = 5;
  if (*a != 99)
  {
    // Do stuff
  }
}

gcc is perfectly entitled to translate this as:

int poo (int *a, short *p)
{
  *p = 5;
  *a = 99;
}

Andrew.

[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