what's the difference between typed_object and any_object ?

General help with the eC language.
Post Reply
nicktick
Posts: 17
Joined: Tue Nov 13, 2012 8:34 pm

what's the difference between typed_object and any_object ?

Post by nicktick »

would you give me an exmaple for demoing their differences ? and both of them are only used for declaration of function, right ?
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: what's the difference between typed_object and any_objec

Post by jerome »

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
Post Reply