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

Johan Schoeman

Expert
Licensed User
Longtime 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: Copy
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: Copy
#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
 
This seems to work:
Code: Copy
#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?
 
Upvote 0
This seems to work:
Code: Copy
#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?

you got it, it's called forward declaration.

https://en.wikipedia.org/wiki/Forward_declaration
 
Upvote 0
Upvote 0
...and your anti scream recipe for this sceneario...
Code: Copy
#if C
   
void foo_1 (void)  {  foo_2(); }
void foo_2 (void)  {  foo_1(); }

#End if
I do a nap and let the compiler screaming :p
Because with recursive calls, i'm not sure that even the "forward declaration" change something.

Tell me, your dog run after his tail ? :D
 
Upvote 0
Back
Top