No announcement yet.

Forward reference of function

  • Filter
  • Time
  • Show
Clear All
new posts

  • Forward reference of function

    I keep hitting compiler errors because it cannot see that a function that I wrote is actually defined (i.e. a forward referencing problem).
    Extract from code:

    MagicCode 0 (PostActivateForm):
    if(CurrentForm == 9) // terminal screen?
    HC_ClearTerminal(); // clear terminal and set color and cursor

    MagicCode 2 (global code):
    func HC_ClearTerminal()
    // bla bla bla

    Compiler errors I am getting:
    • 'HC_ClearTerminal' not found (line...)
    • context error for unknown 'HC_ClearTerminal'
    This only happens when I call a function from a PostActivateForm type MagicCode.
    If I do something similar, but from another piece of global code, then all works fine (also if I use the function before I declare it).
    Even in the resulting code (the 4DGenieS file), you can see the declaration of MC2 is included before it's use in MC0, so I cannot understand why the compiler is not happy.

    How can I overcome this? Because I cannot declare a function in MagicCode0 (because it is actually a part of the ActivateForm() function).
    And I have found no manner to do a forward define (as you would do in the .H file in a C project).
    According to the manual (4DGL programmers reference manual, rev 6.1, page 44), what I am doing is fine ('.. the ordering of functions no longer needs to be ordered with strict backward referencing..') Indeed I do find this statement to hold for 'normal' global code, even if programmed in different global magic code modules. But apparently not for PostActivateForm code...

    PS1: I am having the same problem if I want to use a globally defined variable here.
    PS2: to make it even more funny, when I set up a timer function in that same MC0, with a callback function in MC1 (global), then this works fine. This is probably because the compiler doesn't treat the variable used as a function, just as a piece of parameter text (the code reads like this: sys_SetTimerEvent(0, Timer0Timeout); whereby func Timer0Timeout() is defined in MC1

    Any help? Much appreciated.

    Thanks - Hennie Tempelman

  • #2
    Found the answer by accident... Seemed that the MC2 never got compiled... nor got a warning... because you can have only one global module?
    When I moved the MC2 (global) code to MC1 (global), all went fine.
    So much for applying a bit of structure to your software. Apparently you must write everything in one big lumpy module.
    Even though the environment will let you define multiple global modules.
    Anyway, progressing again, and the issue above can be closed and hope it is useful info for the rest of the community.


    • #3
      Hi Hennie,

      Welcome to the forum!

      Yes, you should only have one Magic Code for every insertion point in your application.
      We will update the document for our users to be further guided. Thank you.

      Best Regards,