Announcement

Collapse
No announcement yet.

I thought this wasn't allowed....

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • I thought this wasn't allowed....

    ....but apparently it's okay.
    Code:
    REM **************************************              '
    REM * Enter a line of text on the screen *              '
    REM **************************************              '
    REM * Written in CCv 4.04.               *              '
    REM **************************************              '
                                                            '
    DECLARE FUNCTION ScreenInput(LONG, _                    '
                                 LONG, _                    '
                                 LONG) AS STRING'           '
                                                            '
    FUNCTION ScreenInput(SiRow AS LONG, _                   '
                         SiCol AS LONG, _                   '
                         SiLen AS LONG) AS STRING           '
        LOCAL t       AS LONG                               '
        LOCAL x       AS LONG                               '     
    etc, etc, and so on and so forth
        END FUNCTION
    This snippet is in an #INCLUDE file (the 2nd or 3rd #INCLUDE) and was DECLARE'd before in the main file.

    Thought duplicate DECLARE's was illegal but it seems it's legal in that the program compiles and runs fine (so far as it's developed).
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

  • #2
    What would make you think you can't have two DECLARE's as long as they're the same? Did you read that in the PowerBASIC doc? Could you please show us the location so we can check it out?

    Thanks!

    Bob Zale
    PowerBASIC Inc.

    Comment


    • #3
      What am I not seeing here? The top structure is a function declaration and the lower is its implementation?

      Code:
      #Compile Exe
      #Dim All
      Declare Function Foo() As Long
      
      Function Foo() As Long
        Foo=1
      End Function
      
      Function PBMain () As Long
        Print "Foo() = "Foo()
        Waitkey$
        
        PBMain=0
      End Function
      Fred
      "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

      Comment


      • #4
        The compiler will only flag a declare or procedure header as a 'duplication error' if it finds..

        - A prior DECLARE not matching number and type of parameters and return type
        - A prior procedure header not matching number and type of parameters and return type

        i.e., moot duplicates are ignored.

        Remember what a DECLARE really is: It is a compiler directive which says, "when you see this symbol, this is what it means".

        In this case, when compiling the executable statement...
        Code:
         Print "Foo()=" & Foo()   ' note the required '&' here!!
        ...if the compiler had not yet encountered the symbol "Foo" it could not know what to do. However, you had already told the compiler (via DECLARE and by Procedure Header) what "foo" means when encountered.

        You don't need the DECLARE here, but only because the procedure header for 'Foo' physically precedes its use in an executable statement... but it never hurts to have a DECLARE, unless you have mismatched parameters or return data types.

        MCM
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          BTW, if you use the explicit CALL verb, the compiler does not care where the procedure header physically resides in the source module.

          That may also apply to to DECLARE statements, but of that I am not certain.

          Of course using the CALL form precludes the use of a FUNCTION name as a though it were a variable and you'd need two lines of code...
          Code:
            CALL Foo () TO S$
            PRINT "Foo()=" & S$
          But I suppose you could MACRO it (to make MACRO a verb)...
          Code:
          MACRO CallFunc (Funcname) 
            Macrotemp S 
            DIM S AS STRING
            CALL funcname to S
          END MACRO = S 
          ...
             PRINT "Foo()=" & CallFunc (Foo)
          ...something like that, anyway

          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            I guess I got confused. Re: CC3.04 book, Page 266
            PowerBasic does not support multiple declarations of an imported Sub/Function. That is, if two or more DECLARE statements use the same ALIAS name, a compile-time Error 466 ("Duplicate name definition") will occur
            Don't have the 4.x book (yet). Relying on the HELP file(s) for the time being.
            There are no atheists in a fox hole or the morning of a math test.
            If my flag offends you, I'll help you pack.

            Comment


            • #7
              PowerBasic does not support multiple declarations of an imported Sub/Function. That is, if two or more DECLARE statements use the same ALIAS name, a compile-time Error 466 ("Duplicate name definition") will occur
              Really? I thought that restriction was eliminated in 8.00. It was one of my complaints.

              There has to be restriction on the SYMBOL name ("FOO"), but the ALIAS thing - if the above sentence may be taken literally - well that looks like either a reversion back to the past or a help-file-needs-help thing.

              MCM
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment

              Working...
              X