Objective-C implicit conversion loses integer precision ‘NSUInteger’ (aka ‘unsigned long’) to ‘int’ warning

The count method of NSArray returns an NSUInteger, and on the 64-bit OS X platform NSUInteger is defined as unsigned long, and unsigned long is a 64-bit unsigned integer. int is a 32-bit integer. So int is a “smaller” datatype than NSUInteger, therefore the compiler warning. See also NSUInteger in the “Foundation Data Types Reference”: … Read more

How do I avoid implicit conversions on non-constructing functions?

Define function template which matches all other types: void function(int); // this will be selected for int only template <class T> void function(T) = delete; // C++11 This is because non-template functions with direct matching are always considered first. Then the function template with direct match are considered – so never function<int> will be used. … Read more

Overload resolution failure when streaming object via implicit conversion to string

14.8.1/4 in C++98 Implicit conversions (clause 4) will be performed on a function argument to convert it to the type of the corresponding function parameter if the parameter type contains no template-parameters that participate in template argument deduction. Here you would like an instantiation of template <class charT, class traits, class Allocator> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, … Read more

Why is this happening with the sizeof operator when comparing with a negative number? [duplicate]

sizeof returns size_t which is unsigned and so -1 is being converted to a very large unsigned number. Using the right warning level would have helped here, clang with the -Wconversion or -Weverything(note this is not for production use) flags warns us: warning: implicit conversion changes signedness: ‘int’ to ‘unsigned long’ [-Wsign-conversion] if (sizeof(int) > … Read more