Re: export & public

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

I read the doc about scope and the difference between public and export is not explained. Both words seem to means the same.
Plus what it the effect of: public include .... ?

They are similar. Both allow symbols to be exposed to a file that includes the file in which they are declared. public symbols can possibly be seen by the files that included the file, etc, assuming public include is used to include the files. Here is a simple example:

libA.e said...
export constant A_EXPORT = 0 
public constant A_PUBLIC = 0 
       constant A_LOCAL  = 0 
libB.e said...
public include libA.e 
  -- these are legal: 
? A_EXPORT 
? A_PUBLIC 
  -- this is not: 
? A_LOCAL 
libC.e said...
include libA.e 
  -- these are legal: 
? A_EXPORT 
? A_PUBLIC 
  -- this is not: 
? A_LOCAL 
libD.e said...
public include libB.e 
  -- this is legal: 
? A_PUBLIC 
  -- these are not: 
? A_EXPORT 
? A_LOCAL 
libE.e said...
include libD.e 
  -- this is legal: 
? A_PUBLIC 
  -- these are not: 
? A_EXPORT 
? A_LOCAL 
libF.e said...
include libC.e 
  -- these are not legal 
? A_PUBLIC 
? A_EXPORT 
? A_LOCAL 

I've just shown several different files that have varying visibility of the symbols in libA.e. Of course, only libA.e can use symbols declared as local (i.e., no modifiers), just like 3.1. And we can see that all the files that directly include libA.e can use A_EXPORT and A_PUBLIC. None of the files that did not directly include libA.e can use A_EXPORT.

The key difference shows up between libE.e and libF.e. Notice that libE.e can still use A_PUBLIC, while libF.e cannot. This is because:

libE.e includes libD.e public includes libB.e public includes libA.e
libF.e includes libC.e includes libA.e

Basically, the public include directive passes along any public symbols it can see in any other files. It may have been able to see them because it directly included the file, or because of other public include directives in files it included (as the example above shows).

Mattt

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

Search



Quick Links

User menu

Not signed in.

Misc Menu