Giter Site home page Giter Site logo

Comments (9)

bstellato avatar bstellato commented on June 5, 2024

I like the char option. It seems the easiest solution. What do you think @goulart-paul ?

from qdldl.

goulart-paul avatar goulart-paul commented on June 5, 2024

The only purpose of the above is to ensure that the QDLDL_bool we define will make sense to the C compiler, which will not be the case if we have a C89 only compiler and we ask for _Bool.

It might be better to check for compiler support of '_Bool' in cmake directly before building qdldl, using something like https://cmake.org/cmake/help/v3.0/module/CheckCSourceCompiles.html

The process in cmake could be:

  1. Include a small check in cmake to see if test code with a _Bool compiles.

  2. Define QDLDL_BOOL_TYPE accordingly within cmake, taking it as either int or _Bool depending on the outcome of step 1.

  3. Put typedef @QDLDL_BOOL_TYPE@ QDLDL_bool; into qdldl_types.h.in as a single line instead of switching on __STDC_VERSION__ as above.

In this way the header would be unambiguous about the logical type we use and we would be sure that the header is consistent with what we actually built.

If the above seems like it would fix the problem with C++ compatibility I can try it.

from qdldl.

mlubin avatar mlubin commented on June 5, 2024

From what I can tell, _Bool will not work for C++. It's not defined in the C++ standard or supported by the C++ compilers that I tried. I also tried using bool and including stdbool.h but that didn't work either on the C++ side.

from qdldl.

goulart-paul avatar goulart-paul commented on June 5, 2024

Another option would be to just make it an enum, e.g.

typedef enum _QDLDL_bool { false, true } QDLDL_bool;

That ends up as the same size as int I think, which is not quite as compact as it could be but better than nothing. The only point of any of this was to avoid it being long long when we define QDLDL_int that way.

from qdldl.

mlubin avatar mlubin commented on June 5, 2024

enums are also a bit problematic to use at library boundaries because their size is not defined in the standard. If you compile qdldl into a shared library with compiler 1 and try to link to it with compiler 2, you have a similar issue.

Do you have an objection to char?

from qdldl.

goulart-paul avatar goulart-paul commented on June 5, 2024

Not really, no. It was unclear to me when writing this whether forcing the type to be 8 bits exactly might be slower than allowing it to be whatever is the most efficient size for the platform (i.e. I would have preferred int_fast8_t, but that is also C99 only). I can't say for sure if that's anything beyond a hypothetical concern though.

from qdldl.

mlubin avatar mlubin commented on June 5, 2024

That's also hard to test since I don't know on which platforms int_fast8_t is strictly larger than char.

If char is too awkward as a bool store, int is also reasonable. You can also ask for an int* for the bool storage in the header and cast it to something else. You have to be careful about memory alignment issues if you're casting it to a pointer to a type of a different size than int, however.

from qdldl.

goulart-paul avatar goulart-paul commented on June 5, 2024

I have proposed a fix in #12 that changes the definition of the bool type to unsigned char.

from qdldl.

goulart-paul avatar goulart-paul commented on June 5, 2024

fixed in #12

from qdldl.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.