Re: public, export

new topic     » goto parent     » topic index » view thread      » older message » newer message
jiri said...

The new version of 4.0 docs is pretty good already. Even the section dealing with scopes has been improved, but one thing is still puzzling me: the difference between public and export, if any. These terms seem to be used interchangeably in the libraries. If they are indeed synonyms, why do we have to have such stupid, misleading duplicity, well, I mean duplication? (Sorry, English is only my third language...)

jiri

They are identical in every way but one.

Sometimes, in large multi-file libraries, it makes sense to declare different public symbols in different file, but still have the user of the library only include the main file. (win32lib is a good canidate for this)

The problem with public is that if you declare the symbol in a different file, other than win32lib.ew, then a user who includes win32lib.ew normally would not be able to see that symbol.

This is why we have 'public include' - win32lib.ew can become a file that just public include's all the other files. Then the user sees the public symbols regardless of which file they were originally declared in.

However, this creates a new problem. The 'public include' solution would make public no better than global, since ALL of the symbols that are shared with other files will be exposed in the main api file (e.g. win32lib.ew) Sometimes you need to share symbols between two different files of a multi-file library, but still keep it as an internal symbol and hide it from the user.

That is where export scope came from. export is identical to public in all ways but one - while public include will propagate public symbols to the next level, it will not propagate export symbols. To see these, you must still include the file that declares the symbol directly. Thus, public symbols are meant to be shared from a library and seen by a user, export symbols are meant to be used internally to the library only but between files.

So we have a range of: private - local - export - public - global

(You'd probably never need the export scope in a single file library.)

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu