default private public

General help with the eC language.
Post Reply
redj
Posts: 105
Joined: Sun Jan 17, 2010 10:03 am

default private public

Post by redj »

Question from JF:
What does private and default mean at the source level (outside a class)?

-redj
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: default private public

Post by jerome »

(See also page 86-92 of the Tao)

The meaning of private / public is very different in eC (compared to e.g. C++).

Its meaning is the same inside and outside a class/struct .

public means it's accessible outside the 'executable module' (It only makes a different with a shared library).
private means it's only accessible from within the 'executable module'
static means it's only accessible from within the source file module (.ec file)

Now for the current limitations:

We're missing the 'static' declaration inside classes/structs. This limits the value of the 'static' access control in general, because anything that is non-static must use only non-static types.
Thus if you need to use any non-static type in any of the methods of the class you want to make static, that's not possible at the moment.

There are some special features that won't work well if you declare your constructs private, because it restricts the access to those constructs from within your module, and those features are implemented in a shared library (e.g. in the ecere shared library). Some of these should probably be fixed/improved.

See attached the latest test for access control.
Attachments
override.ec
(479 Bytes) Downloaded 1007 times
publicErrors.ec
(1.98 KiB) Downloaded 1034 times
static.ec
(2.05 KiB) Downloaded 1014 times
test.ec
(2.9 KiB) Downloaded 983 times
inheritance.ec
(151 Bytes) Downloaded 977 times
privacy.ec
(7.02 KiB) Downloaded 1004 times
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: default private public

Post by jerome »

Sorry I forgot all about 'default'!

default brings eC in a 'C' mode, where nothing gets mangled at all (No name spaces, structs behave like in C and do not create a type (no struct class gets created)).

If you are not inside a namespace, a global function declared does not get mangled in any way and can be called as it is in C. The default keyword allows to do that even though you are inside a namespace.

Anything inside a .h file automatically is read in as if in the 'default' mode.
To have it understood as eC, you can use the .eh extension, although it is rarely necessary to use headers with eC, preferring the 'import' mechanism. (It would still be necessary to share e.g. C macros).

Using private, static, or public goes back in eC mode.
Post Reply