Re: Refining points-to information



On 26 Apr 2006 01:13:49 -0400, "dz" <drizzle76@xxxxxxxxx> wrote:

Spefically, if a local
variable's address is not taken, perhaps it can be not included in the
points to set. Similarly. can't I assume that if it is a int* then it
would not point to a function. Are these also unreasonable ?

It's very hard to reason intelligently about pointers in C/C++ because
these languages allow pointer arithmetic and casting conversions.

You can certainly tell by examination whether a particular local
variable's address was taken, but you can't assume no aliasing in the
negative case if any other local variable's address was taken and
arithmetic was performed on that pointer.

Similarly wrt limiting the set of types that could be pointed to ...
you're also short of luck because any type of pointer may be cast to
or from a void pointer. Realistically, you can't assume the type of
the target matches the type of the pointer to it unless you also know
the entire chain of casts and arithmetic that has been performed.

George
[You can certainly assume that a local that never has its address taken
isn't aliased. I realize that people write code like this snippet, but
it's forbidden by the standard and people deserve what they get;

int a;
int b;
int c;

int *p = &a;
p[2] = 12; // change c

You are correct that you can't make type assumptions without very
thorough and often impossible type analysis. - John]


.



Relevant Pages

  • swap using pointers
    ... int swap; ... incompatible pointer type ...
    (comp.lang.c)
  • Re: Reading a string of unknown size
    ... "Don't cast return value of malloc() in C. ... It is entirely possible for an int to be returned by a ... function using a different method than that used to return a pointer. ...
    (comp.lang.c)
  • Re: Is this code valid
    ... | the program, or a null pointer, or a pointer to non-modifiable ... is promoted to `unsigned int'. ... implementations), the cast is therefore necessary. ...
    (comp.lang.c)
  • Re: A little help please
    ... >>You don't need the cast. ... void* to another pointer type. ... if arr points to first element of int array then I thought by ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Memory Structure Pointer Problems
    ... typedef struct sta { ... char* name; ... int num_cmpnds; ... A pointer to a struct cmp is almost ...
    (comp.lang.c)