External Functions

Functions by default have global scope within a project

A function defined within any file in a project may be called from any other file.

extern keyword not required, but function prototype is required in calling file or #included header file

The only thing required to access the externally defined function is a function prototype in the calling file or a #included header file. The use of header files for this purpose is extremely common. The functions available in the standard C library all have associated header files that may be included in your source files. These header files contain the function prototypes for the library functions, which let the compiler know how to handle these function calls even though the definition of the function is somewhere else.

Note: It is perfectly valid to use the extern keyword in front of a function definition, but it isn't strictly required.

ExternalFunction.png
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.