Re: Questions about Void, NULL and 0x0

"Eric Bezault ericb-D6Qt/9opevxWk0Htik3J/[email protected] [gobo-eiffel]" <[email protected]> Fri, 8 Nov 2019 21:07:54 +0100
Newsgroups gmane.comp.lang.eiffel.gobo.general
Message-ID <[email protected]>
Hi Germàn,

Without seeing your code, it's hard to say, but I would suspect
that when you write:

    if attached get_string as p then

`get_string` is of type POINTER. If so, then you should know that
POINTER is an expanded class, and therefore can never be void.
So `attached get_string` will always return True. It's as if you
write:

    get_string /= Void

It's not different from:

    int := 0
    if attached int as i then

This will always return True because an INTEGER is never Void.
In case of INTEGER, we have:

    attached int   ->  True
    int /= Void    ->  True
    int /= 0       ->  False

In case of POINTER we have:

    attached get_string           -> True
    get_string /= Void            -> True
    get_string /= default_pointer -> False
    get_string.is_default_pointer -> True

-- 
Eric Bezault
mailto:ericb-D6Qt/9opevxWk0Htik3J/[email protected]
http://www.gobosoft.com


On 08/11/2019 20:36, Germán Arias [email protected] [gobo-eiffel] wrote:
> Hi,
> 
> Attached is a simple Void test. As you can see the c function return a
> char that is not attached. However it pass the test "attached get_string
> as p then". With gec it compiles and run without problem. The output is:
> 
> [german@localhost void-test]$ ./void_test
> p is attached.
> 0x402482
> UH��H�E�]�UH��H�� ���E�
> 
> With ISE (C inline is different but is the same C function) it compiles
> but crash at run time. The output is:
> 
> [german@localhost void-test]$ ./void_test
> p is attached.
> 0x0
> 
> void_test: system execution failed.
> Following is the set of recorded exceptions:
> 
> ******************************** Thread exception
> *****************************
> In thread           Root thread            0x0 (thread id)
> *******************************************************************************
> -------------------------------------------------------------------------------
> Class / Object      Routine                Nature of exception
> Effect
> -------------------------------------------------------------------------------
> VOID_TEST           root's creation        Segmentation fault:
> <00007F574488E558>                         Operating system signal.
> Exit
> -------------------------------------------------------------------------------
> VOID_TEST           root's creation
> <00007F574488E558>                         Routine failure.
> Exit
> -------------------------------------------------------------------------------
> 
> As far as I know 0x0 mean a NULL pointer, right?. So why it pass the
> attached test? In this case the application compiled with gec don't
> crash, But have some crashes with some eiffel-iup examples. What is
> wrong here? I misunderstood something about Void at Eiffel? I didn't ran
> a test on Liberty Eiffel, since I don't have problems with it. Any
> advice? Thanks in advance.
> 
> Germán


------------------------------------
Posted by: Eric Bezault <ericb-D6Qt/9opevxWk0Htik3J/[email protected]>
------------------------------------

To Post a message, send it to:   [email protected]
To Unsubscribe, send a blank message to: [email protected]