Coder Social home page Coder Social logo

Missing includes about imgui HOT 10 CLOSED

spworley avatar spworley commented on May 14, 2024
Missing includes

from imgui.

Comments (10)

septag avatar septag commented on May 14, 2024

had that problem too, fixed it by adding those two includes to imgui.cpp

from imgui.

ocornut avatar ocornut commented on May 14, 2024

Thanks! Shouldn't either limits.h or stdint.h be enough? Is the error you were getting the lack of INT_MAX only? Trying to be very explicit and document why such and such are included in the code. If you could paste the compilation error it would be great.

from imgui.

septag avatar septag commented on May 14, 2024

Sure, (compiled with clang)

imgui.cpp:912:27: error: use of undeclared identifier 'INT_MAX' FocusIdxRequestCurrent = INT_MAX;

imgui.cpp:2843:31: error: unknown type name 'intptr_t'; did you mean '__intptr_t'? const void* ptr_id = (void*)(intptr_t)int_id;

first one solved by including limits.h, second one by including stdint.h

from imgui.

ocornut avatar ocornut commented on May 14, 2024

Thanks, it is fixed in trunk now.

from imgui.

ocornut avatar ocornut commented on May 14, 2024

Just had a report that limits.h doesn't exist on OSX.
Could you tell me if include stdint.h only fix the build on your setup? (wikipedia implies that stdint.h is a superset of limits.h). Thanks.

from imgui.

septag avatar septag commented on May 14, 2024

Removing limits.h , still brings INT_MAX not found error
However there is INT32_MAX defined inside stdint.h, I guess you could use that one.

from imgui.

ocornut avatar ocornut commented on May 14, 2024

I removed the need for INT_MAX to simplify anyway, it was only used as a marker for a value being "unset".

from imgui.

Pagghiu avatar Pagghiu commented on May 14, 2024

I couldn't miss the opportunity of commenting issue #1 ;-)
Some time ago I've spotted some smart code to get Min and Max Value of any integer type from the Cap'n'Proto source code without using limits.h.
Do not worry about the constexpr thing, it can be disabled entirely (and it is for MSVC by default already).

#if _MSC_VER

#define KJ_CONSTEXPR(...) __VA_ARGS__
#define RR_CONSTEXPR(...) __VA_ARGS__
// Use in cases where MSVC barfs on constexpr. A replacement keyword (e.g. "const") can be
// provided, or just leave blank to remove the keyword entirely.
//
// TODO(msvc): Remove this hack once MSVC fully supports constexpr.

#else  // _MSC_VER
#define KJ_CONSTEXPR(...) constexpr
#define RR_CONSTEXPR(...) constexpr
#endif

    class MaxValue_ {
    private:
      template <typename T>
      inline KJ_CONSTEXPR() T maxSigned() const {
        return (1ull << (sizeof(T) * 8 - 1)) - 1;
      }
      template <typename T>
      inline KJ_CONSTEXPR() T maxUnsigned() const {
        return (T) ~static_cast<T>(0u);
      }

    public:
    #define _kJ_HANDLE_TYPE(T) \
      inline KJ_CONSTEXPR() operator   signed T() const { return MaxValue_::maxSigned  <  signed T>(); } \
      inline KJ_CONSTEXPR() operator unsigned T() const { return MaxValue_::maxUnsigned<unsigned T>(); }
      _kJ_HANDLE_TYPE(char)
      _kJ_HANDLE_TYPE(short)
      _kJ_HANDLE_TYPE(int)
      _kJ_HANDLE_TYPE(long)
      _kJ_HANDLE_TYPE(long long)
    #undef _kJ_HANDLE_TYPE

      inline KJ_CONSTEXPR() operator char() const {
        // `char` is different from both `signed char` and `unsigned char`, and may be signed or
        // unsigned on different platforms.  Ugh.
        return char(-1) < 0 ? MaxValue_::maxSigned<char>()
                            : MaxValue_::maxUnsigned<char>();
      }
    };

    class MinValue_ {
    private:
      template <typename T>
      inline KJ_CONSTEXPR() T minSigned() const {
        return 1ull << (sizeof(T) * 8 - 1);
      }
      template <typename T>
      inline  KJ_CONSTEXPR() T minUnsigned() const {
        return 0u;
      }

    public:
    #define _kJ_HANDLE_TYPE(T) \
      inline KJ_CONSTEXPR() operator   signed T() const { return MinValue_::minSigned  <  signed T>(); } \
      inline KJ_CONSTEXPR() operator unsigned T() const { return MinValue_::minUnsigned<unsigned T>(); }
      _kJ_HANDLE_TYPE(char)
      _kJ_HANDLE_TYPE(short)
      _kJ_HANDLE_TYPE(int)
      _kJ_HANDLE_TYPE(long)
      _kJ_HANDLE_TYPE(long long)
    #undef _kJ_HANDLE_TYPE

      inline KJ_CONSTEXPR() operator char() const {
        // `char` is different from both `signed char` and `unsigned char`, and may be signed or
        // unsigned on different platforms.  Ugh.
        return char(-1) < 0 ? MinValue_::minSigned<char>()
                            : MinValue_::minUnsigned<char>();
      }
    };

    static KJ_CONSTEXPR(const) MaxValue_ maxValue = MaxValue_();
    // A special constant which, when cast to an integer type, takes on the maximum possible value of
    // that type.  This is useful to use as e.g. a parameter to a function because it will be robust
    // in the face of changes to the parameter's type.
    //
    // `char` is not supported, but `signed char` and `unsigned char` are.

    static KJ_CONSTEXPR(const) MinValue_ minValue = MinValue_();
    // A special constant which, when cast to an integer type, takes on the minimum possible value
    // of that type.  This is useful to use as e.g. a parameter to a function because it will be robust
    // in the face of changes to the parameter's type.
    //
    // `char` is not supported, but `signed char` and `unsigned char` are.

    #undef KJ_CONSTEXPR

the way you use it is

unsigned int myVariable;
//... myVariable gets assigned somewhere....
if(myVariable > (int)maxValue) // THIS equals myVariable > INT_MAX
{

}

from imgui.

ocornut avatar ocornut commented on May 14, 2024

Welcome to issue 1.
Not including that sort of code in ImGui! :)
I sort of see why it may be essential to Cap'n'Proto which needs reliable data on every type, we just want INT_MAX. Worst case we can add an ifdef include thing to cope with a few bad cases. I have readded <limits.h> from imgui.cpp to see if anyone reacts since I don't have a proper recorded reason for not including it.

from imgui.

Pagghiu avatar Pagghiu commented on May 14, 2024

That's fine, I was just looking for a realistic excuse to be featured in issue 1 😆

from imgui.

Related Issues (20)

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.