Edit:
Casting is the only approach if you want to lock the compiler on one instance in a portable way. This is great if you know what you are doing, for example. that you can guarantee that the result of atoi will never be negative.
In GCC, you can disable all sign conversion warnings with the -Wno-sign-conversion flag. There is also -Wno-sign-compare (for things like 2u > 1 ), but this will not be relevant unless you use -Wextra .
You can also use diagnostic pragmas , for example
#pragma GCC diagnostic ignored "-Wsign-conversion"
There are several warnings in MSVC regarding signed / unsigned character mismatch, for example:
To disable the warning in MSVC, you can add #pragma warning , for example.
#pragma warning (disable : 4267)
or add the /wd4267 flag to the compiler options.
Perhaps you should use strtoul instead of atoi .
size_t a = strtoul(val, NULL, 0);
(There is no warning only if size_t is sized as unsigned long . On most platforms this is true, but it is not guaranteed.)
The advantage is that you can perform error checking with this function, for example
#include <stdlib.h>
source share