Message from C, C++ discussions

November 2019

— Not defined

— 

I'm not positive but I think it's for the preprocessor/lexer or whatever because the compiler is gonna need to know that a function named test exists so I'm guessing it can be linked together properly

— Because now i use c to program mcu nrf52840 using segger IDE. when i put it under the other function it cannot detect the function. usually compiler will give suggestion function as we type. so strangeee

Message permanent page

— "The required behaviour of C89 when encountering a function call for which no definition or prototype is available is to assume that it returns an int and has the number and types of the arguments that you supply in the call. If you subsequent call it with different argument types that cannot be legally implicitly cast, or a different number of arguments, the compiler will reject the code.

The compiler or linker will complain when it eventually finds a mis-matching definition. The use of a prototype allows the compiler to generate the error at the call rather than the definition, of when trying to link the definition from another module. So in short don't do it if you want the compiler to help you write working code!

In C99 and C++ prototypes are required if the definition is not already visible.

"

Message permanent page

— Thanks. i dont understand.😆😆

— It does not need this.

To call a function, it has to be declared first, before calling, but does not need defining.
That is, you can only declare the function, but define it later in the source file or even in another source file. This is what we have in C++.

In classic C you even don't need to declare a function, the call just will not be checked on correctness of the parameters.

You needed to put your function upper in the file only because you don't you separate pre declaration of the function.
But definition of function is always also a declaration, hence the compiler can use this function lower in the file

Message permanent page

— This is better. thanks

— But i dont understand the pre declaration of the function. anyway will google it.

— Read about forward declaration.

— Hi there! Join TimesPoints using my referral link & earn 100 Bonus Points. Click here https://www.timespoints.com/refer-earn?referral_code=DQNNRX to join. #TimeIsMoney with TimesPoints!

Message permanent page

— You declare a function and since this point you can use it.

— What is the best channel on YouTube to learning programming?