Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Missing includes #1

Closed
spworley opened this issue Aug 11, 2014 · 10 comments
Closed

Missing includes #1

spworley opened this issue Aug 11, 2014 · 10 comments
Labels

Comments

@spworley
Copy link

When compiling with gcc 4.6 in Linux, two needed includes are missing from imgui.cpp:
limits.h
stdint.h

@septag
Copy link
Contributor

septag commented Aug 11, 2014

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

@ocornut
Copy link
Owner

ocornut commented Aug 11, 2014

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.

@septag
Copy link
Contributor

septag commented Aug 11, 2014

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

@ocornut
Copy link
Owner

ocornut commented Aug 11, 2014

Thanks, it is fixed in trunk now.

@ocornut ocornut closed this as completed Aug 11, 2014
@ocornut
Copy link
Owner

ocornut commented Aug 11, 2014

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.

@ocornut ocornut reopened this Aug 11, 2014
@septag
Copy link
Contributor

septag commented Aug 11, 2014

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.

@ocornut ocornut added the bug label Aug 11, 2014
@ocornut
Copy link
Owner

ocornut commented Aug 12, 2014

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

@Pagghiu
Copy link
Contributor

Pagghiu commented May 17, 2016

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
{

}

@ocornut
Copy link
Owner

ocornut commented May 17, 2016

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.

@Pagghiu
Copy link
Contributor

Pagghiu commented May 17, 2016

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants