« first day (2816 days earlier)      last day (42 days later) » 

9:53 AM
Is it that legal only declaring a funciton without providing its implementation in C and C++ if the said function would not be invoked anywhere in the project?

Here is the [simple test](godbolt.org/z/8j6PcqMdG) I did. It's amazing that it compiles without any complain.

#include <iostream>

int foo(int(a)){
    std::cout << a << std::endl;
    return a;
};

int goo(int(a));

int main()
{
    foo(1);

    return 1;
}
 
 
1 hour later…
11:07 AM
Seems fine to me. But maybe just because I've seen it a bunch. Never bothered to look up if that's formally undefined behavior.
Never seen it cause issues though
 
 
3 hours later…
2:33 PM
@John It's perfectly fine and happens all the time. It won't typically work for virtual functions though. With them, if you declare it you also need to define it, or you'll (at least usually) get a link error.
 

« first day (2816 days earlier)      last day (42 days later) »