0

I get this weird warning message in Visual Studio Code the whole time and have no idea what else I should change.

Message:

warning: implicit declaration of function 'showMenu' [-Wimplicit-function-declaration]

This is the code:

#include <stdio.h>

int main() {
   
   showMenu();

    return 0;
}

int showMenu() {
   
    printf(" Herzlich willkommen \n");
    printf("(0) Telefonnummern anzeigen\n");
    printf("(1) Neue Nummer hinzufügen\n");
    printf("\n\n");
  
    return 0;
}

Hope someone can help me.

greetings

" ; if ($?) { gcc Adressbuch.c -o Adressbuch } ; if ($?) { .\Adressbuch }
Adressbuch.c: In function 'main':
Adressbuch.c:5:4: warning: implicit declaration of function 'showMenu' [-Wimplicit-function-declaration]
    showMenu();
    ^~~~~~~~
 Herzlich willkommen 
(0) Telefonnummern anzeigen
(1) Neue Nummer hinzuf├╝gen

I get the results, but with the error message in it.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
Jason
  • 1
  • 1
  • 3
    Nothing weird at all - you're *using* the function before you have provided a declaration or definition for it. – Adrian Mole Apr 17 '23 at 10:10
  • Imageine the compiler reading the source from top to bottom.. So he finds tha call of `showMenu()` before the definition and that is the implicit declaration. Just add a prototype `int showMewnu(void);` before the definition of `main()` or just move the definition of `showMenu()` itself before `main()` – Ingo Leonhardt Apr 17 '23 at 10:11
  • BTW: always consider warnings containing the word "implicit" as errors, even if the code once compiled appears to work fine. – Jabberwocky Apr 17 '23 at 12:47

2 Answers2

0

The function shall be declared before its usage as for example before main

int showMenu( void );

int main( void )
{
    //...
}

Pay attention to that the return type int of the function does not make a great sense. You could declare it like

void showMenu( void );
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
0

Just add a prototype to your showMenu function before the main. Example

int showMenu (); //Function prototype here

int main() {
   
   showMenu();

    return 0;
}

int showMenu() {
   
    printf(" Herzlich willkommen \n");
    printf("(0) Telefonnummern anzeigen\n");
    printf("(1) Neue Nummer hinzufügen\n");
    printf("\n\n");
  
    return 0;
}
jvieira88
  • 115
  • 7