realbasic-games
[Top] [All Lists]

Re: Alternate 3D (Chris)

To: REALbasic Games <realbasic-games at lists dot realsoftware dot com>
Subject: Re: Alternate 3D (Chris)
From: Ben Lilburne <bnej at mac dot com>
Date: Wed, 18 May 2005 18:00:53 +1000
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <BEAF8547 dot 317D%acuipka at statrite dot com> <p06200715beb07cc9952a at [192 dot 168 dot 0 dot 101]>
Actually this isn't sending a message to an object at all, and I think your example illustrates this perfectly.

C++ will invoke the function, passing as the 0th parameter the pointer given by the value of x. The function in class a will attempt to de-reference that pointer as a "b" object, but will overrun the memory allocated to the address and you'll get either a SEGV or memory corruption.

Do this in the Objective C (or Smalltalk 80, or Ruby) runtime, and you will get a safe "method not found" error at runtime, with no danger of memory corruption, because in the ObjC RT the object type is included in the object record.

Chris is absolutely right.

Cheers,
Ben

On 18/05/2005, at 4:40 PM, Chris Dillman wrote:
Do you mean like this?

class a{
    public:
    void foo();
    void bar();
};

class b{
    public:
    int y;
    void foo2(){
        y = 100;
    }; };

int main (int argc, char * const argv[]) {

    a my_a;
    int x = &my_a;

    ( (b*) (x) )->foo2();

    return 0;
}


My thoughts if this is what you mean.

1. Memory corruption is bad.

2. You still need to type caste the Ptr to get it by the compiler.

3. You succeed on calling a function on a object that can not support it.
So is this at all useful?


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>