divide.h
#pragma once
#include <assert.h>
inline int divide(int a, int b)
{
assert(b != 0);
return a / b;
}
main.c
#include <divide.h>
int main(void)
{
divide(10, 2);
return 0;
}
I am unable to compile the following solely because of the assert
. If I remove the assert, everything works fine.
$ gcc --version
gcc (GCC) 8.1.0
$ gcc main.c
main.c:(.text+0xf): undefined reference to `divide'
$ gcc main.c -O3 # Compilation with optimization works as asserts are removed.
When placing the defintion of divide
inside a .c
file, everything works fine. However, shouldn't the following also work since the function is declared as inline
?