Loading ...
Sorry, an error occurred while loading the content.

Re: [eiffel_software] Re: once functions

Expand Messages
  • Nicholas Allen
    It can be global within the context of what you are talking about. If I write a shared library I can create a global variable within the context of that shared
    Message 1 of 181 , Mar 1, 2005
    View Source
    • 0 Attachment
      It can be global within the context of what you are talking about.

      If I write a shared library I can create a global variable within the context
      of that shared library. That global variable need not be visible outside of
      the shared library though. eg to applications linked to it. It is still a
      global variable - it just that the library, and all its class, routines etc
      are the only direct clients of the global. As C doesn't have Eiffel's
      selective export, library boundries are often the equivalent.

      For example, a cross platform GUI library might have a global variable for
      Display if it's the X11 implementation. Clearly Display won't be available to
      clients of the library as they should use cross platform interface. However,
      it is still global to the entire library.

      If you are talking within the context of a shared library or a single source
      file it is fine to talk about a global (even if it can't be accessed from
      anywhere) if you qualify that that's what you mean or if it is obvious
      anyway. If your "globe" only consists of one source file, or a library etc
      then a global within that context means just that.

      When one refers to a global outside of any context and not qualified then
      obviously one means a global avaiable to everyone. This is in fact the most
      common kind I have found anyway. eg EV_APPLICATION has one instance and it is
      available to all clients.

      When I used the term global before that is exactly what I meant - available to
      everyone. It is the most common kind.

      I only use globals for creating singleton instances. It is most often the case
      that this singleton is generic enough to be used from any client.

      Unfortunately there isn't another term that I can think of for globals with
      selective export (shared object in Eiffel). Other languages don't have
      selective export and I guess that's why there isn't a term for it.

      In C one should really call a global variable within a source file a static
      variable I guess but I would still call a global variable whose scope was
      limited to a library a global variable.
    • Nicholas Allen
      ... That s easy. It would be done like this: class OPERATIN_ENVIRONMENT shared Directory_separtor : CHARACTER is do result := c_dir_separtor; end shared {NONE}
      Message 181 of 181 , Mar 4, 2005
      View Source
      • 0 Attachment
        > What if a function in the shared section calls an external function,
        > but does it in the style similar to the Directory_separator feature
        > in OPERATING_ENVIRONMENT, where the once function calls a separate
        > external routine?  What happens then?

        That's easy. It would be done like this:

        class
        OPERATIN_ENVIRONMENT

        shared

        Directory_separtor : CHARACTER is
        do
        result := c_dir_separtor;
        end

        shared {NONE}

        c_dir_separator: CHARACTER is
        external
        "C use %"eif_dir.h%""
        alias
        "eif_dir_separator"
        end
        end

        >
        > Also, are you proposing eliminating once routines as well, or only
        > once functions?  I could "get around" your solution by setting a
        > variable from within a once routine. 

        The shared section contains once functions. There would be no such thing as a
        once procedure. If you want then then implement it yourself by setting a
        status variable in the object. No need for language syntax for it - but
        syntactical issue again.
      Your message has been successfully submitted and would be delivered to recipients shortly.