How do I deal with “signed/unsigned mismatch” warnings (C4018)?

It’s all in your things.size() type. It isn’t int, but size_t (it exists in C++, not in C) which equals to some “usual” unsigned type, i.e. unsigned int for x86_32. Operator “less” (<) cannot be applied to two operands of different sign. There’s just no such opcodes, and standard doesn’t specify, whether compiler can make … Read more

Unsigned values in C

Assign a int -1 to an unsigned: As -1 does not fit in the range [0…UINT_MAX], multiples of UINT_MAX+1 are added until the answer is in range. Evidently UINT_MAX is pow(2,32)-1 or 429496725 on OP’s machine so a has the value of 4294967295. unsigned int a = -1; The “%x”, “%u” specifier expects a matching … Read more

Why is −1 > sizeof(int)?

The following is how standard (ISO 14882) explains abort -1 > sizeof(int) Relational operator `>’ is defined in 5.9 (expr.rel/2) The usual arithmetic conversions are performed on operands of arithmetic or enumeration type. … The usual arithmetic conversions is defined in 5 (expr/9) … The pattern is called the usual arithmetic conversions, which are defined … Read more

Difference between size_t and unsigned int?

if it is use to represent non negative value so why we not using unsigned int instead of size_t Because unsigned int is not the only unsigned integer type. size_t could be any of unsigned char, unsigned short, unsigned int, unsigned long or unsigned long long, depending on the implementation. Second question is that size_t … Read more