Casts, types, pointers, and ADDR_EXPR

Andrew Pinski pinskia@physics.uc.edu
Thu May 27 01:58:00 GMT 2004


I am trying to figure out why these two functions act
differently on the tree level as there is an extra cast
in h1 which I think is extraneous.
int h(int g)
{
  const int *x = &g;
  return *x;
}
const int h1(const int g)
{
  const int *x = &g;
  return *x;
}
The reason why I think the cast is extraneous is because
the following code does not produce a cast at all so why
produce one for the address one:
int h2(int g)
{
  const int x = g;
  return x;
}
Getting rid of these casts would help all other optimizations
and will lower the memory usage of gcc slightly at the same time.
Thanks,
Andrew Pinski
PS yes this is the issue I brought up by my fold patch for
ADDR_EXPR but I would like to better understand why there should be
a cast there as the types in my mind equivalent as there is no cast
from "int" to "const int".



More information about the Gcc mailing list