-2

Why when I use getch() function in c++, I should include "conio.h" header file ... while in c it runs without include this file?

I'm using codeBlocks as my IDE.

I expect that I must include "conio.h" in c program also, and I tried to include "stdio.h" and "stdlib.h" in c++ program but there is no result.

genpfault
  • 51,148
  • 11
  • 85
  • 139

1 Answers1

3

Why when I use getch() function in c++, I should include "conio.h" header file ...

C++ requires that identifiers be declared before they are used.

… while in c it runs without include this file?

You are using an implementation of an old version of C in which a function call with an undeclared identifier defaulted to treating the identifier as one for a function with undeclared parameters with return type int.

I'm using codeBlocks as my IDE.

The IDE is irrelevant, except that there are some associations between some IDEs and some sets of development tools. The critical information is the name and version number of the compiler and the switches you are giving to it. Saying what IDE you are using is like saying what picture frame you are using in a question about a picture. The frame does not identify the picture, and the IDE does not identify the compiler you are using inside the IDE.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
  • "You are using an implementation of an old version of C in which a function call with an undeclared identifier defaulted to treating the identifier as one for a function with undeclared parameters with return type int." ........ Is there any more explanation? – Asmaa Abd El-Nasser Jan 07 '23 at 09:08
  • @AsmaaAbdEl-Nasser: In the 1990 version of the C standard, if a function call was made using an undeclared identifier, say `Name`, the identifier was implicitly declared as `extern int Name();`. That was removed in the 1999 C standard, but some compilers still allow it. As I wrote, you have not identified the compiler you are using or the switches. If you are using GCC, you should add `-std=c18` to the switches to use the current standard, and add `-Wall -Werror` to get more warnings and elevate them to errors. If you are using Clang, use `-std=c18 -Wmost -Werror`. – Eric Postpischil Jan 07 '23 at 21:30