Thanks CornedBee,
I do not think compiler checks anything before passing the parameters. I have modified the sample and posted the code below.
You can see ptr1 and ptr2 are aliasing in main. Compile and run ok, any comments?
Code:
__interface IFoo {
public:
virtual int foo ([unique] char *ptr1, [unique] char *ptr2) = 0;
};
class Foo : public IFoo {
public:
int foo (char *ptr1, char *ptr2)
{
char array1[] = "Hello";
ptr1 = array1;
ptr2 = array1; // should be wrong, no aliasing allowed, but compile and run ok
return 0;
}
};
int main()
{
char buf1[] = "Hello World! \n";
char* ptr1 = buf1;
char* ptr2 = ptr2;
Foo f;
// f.foo(ptr1, ptr2);
f.foo(ptr1, ptr1);
return 0;
}
Originally Posted by
CornedBee
The compiler only checks what happens when you pass the pointers. It doesn't care what you do with them afterwards.
regards,
George