c++carmneon

Difference between intrinsic, inline, and external in embedded systems?


I need to know about the difference between intrinsic, inline and external functions in C and C++ programming – specifically, in relation to programming for an embedded, Arm/Neon-based system.


Solution

  • Intrinsic functions

    Intrinsic functions are functions that the compiler implements directly when possible instead of calling an actual function in a library.
    For example, they can be used for optimization or to reach specific hardware functionality.

    For ARM, there exists an intrinsic function (and many others) called __nop(), which inserts a single NOP (No Operation) instruction.

    See the following links for more information:

    Extern functions

    Extern functions tell the compiler that something is defined elsewhere, so it doesn't complain about being undefined or becoming defined multiple times.

    There is almost never any need to use the keyword extern when declaring a function in C or C++, since they normally are linked this way by default.

    See the following links for more information:

    Inline functions

    Inline functions are an optimization technique used by compilers, mostly to reduce execution time.
    For example, if you have a small function (not inlined) with one input parameter, and you call this function multiple times, the processor will (among other things):

    1. Save the parameter
    2. Jump to the function
    3. Execute the function
    4. Store result (if any)
    5. Jump back to previous position.

    Instead, if the function was inlined, it would replace the call statement with the function code itself and then compile the code.

    See the following links for more information: