Can inline function be declared in .h and defined once in .c?
inline function in c
inline
function definitions need to be visible wherever the function is invoked. You can define the function in a .c file if you only want to use it within that .c file, otherwise you need to define it in a .h file so that the definition can be #include
d wherever it is needed.
Yes. It can get messy though here is a good read: http://www.greenend.org.uk/rjk/2003/03/inline.html
You can make a function static inline
and include it on a header file:
square.h:
#ifndef SQUARE_H
#define SQUARE_H
static inline int square(int num) {
return num * num;
}
#endif // SQUARE_H
© 2022 - 2024 — McMap. All rights reserved.