linbox-team / linbox

LinBox - C++ library for exact, high-performance linear algebra
https://linbox-team.github.io/linbox
GNU Lesser General Public License v2.1
81 stars 28 forks source link

linbox/polynomial/dense-polynomial.h cannot be included as is #171

Closed cyrilbouvier closed 5 years ago

cyrilbouvier commented 5 years ago

The file linbox/polynomial/dense-polynomial.h cannot be included as is, the file givaro/givpoly1.h needs to be included before. For example, this code

#include <linbox/polynomial/dense-polynomial.h>

int main (int argc, char *argv[]) {
    return 0;
}

fails to compile (with thousands of lines of error from gcc, so nothing helpful).

But this one

#include <givaro/givpoly1.h>
#include <linbox/polynomial/dense-polynomial.h>

int main (int argc, char *argv[]) {
    return 0;
}

compiles without errors.

The issue is that as a user that want to use the class DensePolynomial, it is easy to find that it is necessary to include linbox/polynomial/dense-polynomial.h but it can be quite complicated to find the other include statement(s) that could be necessary.

In this case, this is easy to fix: adding #include <givaro/givpoly1.h> at the top of linbox/polynomial/dense-polynomial.h (PR is on its way), but i wanted to post this issue as there may be a more general problem of headers implicitly requiring others headers to be included before themselves.

These implicit requirements can be a important complication for the users of the library:

Moreover, the guidelines from the C standard states that

The unit header file shall contain #include statements for all other headers required by the unit header. This lets clients use a unit by including a single header file.

ClementPernet commented 5 years ago

Agreed: there should not be any assumption that givaro/givpoly1.h is included before. There are such omission in many places, but we should fix them by adding the proper missing include as what you're doing in dense-polynomial.h