Ecere SDK/eC Forums
http://www.ecere.com/forums/
Print view

what's the difference between typed_object and any_object ?
http://www.ecere.com/forums/viewtopic.php?f=1&t=373
Page 1 of 1
Author:  nicktick [ Mon Sep 16, 2013 6:10 pm ]
Post subject:  what's the difference between typed_object and any_object ?

would you give me an exmaple for demoing their differences ? and both of them are only used for declaration of function, right ?
Author:  jerome [ Mon Sep 16, 2013 9:59 pm ]
Post subject:  Re: what's the difference between typed_object and any_objec

Hi nicktick,

The distinction between typed_object and any_object is that the object's type information accompanies the object instance itself.

For 'classes' this is not useful much, because the class instance already has type information, but for a function that could accept any object at all (struct, class, int, double, enum, String...) (like the PrintLn() function for example), it's useful to have the full type information to know how to handle each object.

And yes, at the moment it is only for function definition: for parameters, return type and method 'this' type.

At this point in time these eC features are still considered experimental and mostly there to allow for an elegant Ecere API.

One example that uses both is the OnCompare() virtual method of all types:

int typed_object::OnCompare(any_object object)

The 'this' type is typed_object, but the object it is being compared to does not need to be because in this context it will always be of the same type as the object being compared.

The generated C code for the int64 type will look something like:

int Int64_OnCompare(Class _class, int64 * data1, int64 * data2)

Where _class is the extra type information being passed. data1 is the 'this'. You can see data2 does not have a corresponding Class parameter because it is an any_object.

Regards,

Jerome
All times are UTC-05:00 Page 1 of 1