Ecere SDK/eC Forums • View topic - what's the difference between typed_object and any_object ?

Ecere SDK/eC Forums

Ecere Developers Community

what's the difference between typed_object and any_object ?

General help with the eC language.

what's the difference between typed_object and any_object ?

Postby nicktick » Mon Sep 16, 2013 6:10 pm

would you give me an exmaple for demoing their differences ? and both of them are only used for declaration of function, right ?
Posts: 17
Joined: Tue Nov 13, 2012 8:34 pm

Re: what's the difference between typed_object and any_objec

Postby jerome » Mon Sep 16, 2013 9:59 pm

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.


Site Admin
Posts: 621
Joined: Sat Jan 16, 2010 11:16 pm

Return to eC Language

Who is online

Users browsing this forum: No registered users and 3 guests