1

In the following C++ code he make a prototype then called that function without function implementation how is that possible and if that a standard technique in C++ could please mention that concept name or refer some other question that answer my ask, I checked weak function concept but found that it did not match what is here.

void terminalRegisterCommand(const String& name, void (*call)(Embedis*));

terminalRegisterCommand(F("WIFI.STA"), [](Embedis* e) {
        wifiStartSTA();
    });


terminalRegisterCommand(F("WIFI.AP"), [](Embedis* e) {
        wifiStartAP();
    });
  • 3
    This looks like a *forward declaration*. This will compile, though the function must be defined later on for it to link. – cigien Aug 20 '20 at 03:32
  • the problem I did not find any declaration for that prototype so, I supposed I'm miss something in my knowledge of C++. – Muhammad Rabieh Aug 20 '20 at 03:34
  • 1
    A prototype is a declaration. Do you mean something like `void terminalRegisterCommand(const String& name, void (*call)(Embedis*)) { /* some code */ }`. That's a definition. – cigien Aug 20 '20 at 03:38
  • yes I mean no definition exist for that prototype. – Muhammad Rabieh Aug 20 '20 at 03:40
  • 1
    Then you won't get a program that you can run. – cigien Aug 20 '20 at 03:41
  • the problem it is already running, is it mean there is a definition but I can not reach. – Muhammad Rabieh Aug 20 '20 at 03:42
  • 1
    Maybe it's defined in another source file. – paddy Aug 20 '20 at 03:44
  • ok thanks everybody – Muhammad Rabieh Aug 20 '20 at 03:46
  • 2
    It's possible that the function is offered by a library. It's very common to include headers for a library but actually `#include` just inserts the declarations of the header file. So, you could write instead the declaration of a library function directly into the source code which would not make a difference for the compiler. (For the human author, of course, I would not recommend this because it makes the code maintenance more difficult.) FYI: [SO: Is it practical to use Header files without a partner Class/Cpp file in C++](https://stackoverflow.com/a/52646155/7478597) – Scheff's Cat Aug 20 '20 at 05:49

0 Answers0