B4R Question [SOLVED] A real dummy question when using inline C

Discussion in 'B4R Questions' started by Johan Schoeman, Sep 11, 2019 at 5:21 PM.

  1. Johan Schoeman

    Johan Schoeman Expert Licensed User

    I am stuck here....I am trying to call "multiply" from "add" and passing a value of 5 to "multiply" from "add". But I get this error:
    Code:
    b4r_main.cpp:13: error: 'multiply' was not declared in this scope
    Please help this dummy (me) to understand what it is that I am missing....:mad:


    Code:
    #Region Project Attributes
        
    #AutoFlushLogs: True
        
    #CheckArrayBounds: True
        
    #StackBufferSize: 300
    #End Region

    Sub Process_Globals
        
    Public Serial1 As Serial
        
    Private Result, N1, N2 As Int 'ignore
    End Sub

    Private Sub AppStart
        Serial1.Initialize(
    115200)
        
    Log("AppStart")
        N1 = 
    10
        N2 = 
    20
        RunNative(
    "add"Null)
        
    Log("Result: ", Result)
    End Sub

    #if C
    void add (B4R::Object* o) {
       //lower case variables
       b4r_main::_result = b4r_main::_n1 + b4r_main::_n2;
       multiply(5);                //THE ERROR IS HERE! b4r_main.cpp:13: error: 'multiply' was not declared in this scope
    }

    void multiply (int d) {
       //lower case variables
       b4r_main::_result = b4r_main::_n1 * d;
    }


    #End if
     
  2. Johan Schoeman

    Johan Schoeman Expert Licensed User

    This seems to work:
    Code:
    #if C


    void multiply(int d);

    void add (B4R::Object* o) {
       //lower case variables
       b4r_main::_result = b4r_main::_n1 + b4r_main::_n2;
       multiply(5);                //THE ERROR IS HERE! b4r_main.cpp:13: error: 'multiply' was not declared in this scope
    }

    void multiply (int d) {
       //lower case variables
       b4r_main::_result = b4r_main::_n1 * d;
    }


    #End if
    Is this the correct way of doing it?
     
    Peter Simpson and emexes like this.
  3. thetahsk

    thetahsk Active Member Licensed User

    you got it, it's called forward declaration.

    https://en.wikipedia.org/wiki/Forward_declaration
     
    Johan Schoeman likes this.
  4. Johan Schoeman

    Johan Schoeman Expert Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice