Quote:
Originally Posted by
shoaibjameel123
Then I think using size_t or ssize_t would make codes even more portable rather than declaring as int or unsigned int.
Why would you even want to use size_t or ssize_t in main()? It's
defined as int. Using fancy defined types isn't the point -- the point of these types isn't to use them everywhere, the point is to use them when you need them. ssize_t is defined to match certain library and system calls, but main() is not among them. You may not realize it, but main() is called by a library which assumes main() is int main(int argc, char *argv[]). Use anything else, and you're lying to that library, feeding it the wrong kind of function. It
may work if you're lucky on some platforms where size_t and the like are the right size anyway, but change platforms and it could mess up extravagantly. Segmentation faults, and the like. I've experienced this personally.
In other words -- I think you missed the point of my post.
Are you doing calculations with intentional overflow, bit manipultion, or other such things where -- if your integers aren't 32/64/whatever bits, your code is guaranteed to
not work?
These are the sort of circumstances int32_t, uint64_t, et all are designed for.
If you
don't actually need 32 bits and nothing but 32 bits, don't demand it.
And never, ever,
ever use weird types in things already defined as ordinary types, like in main(). If it works at all it's pure coincidence, and can bite you hard when you go to a radically different architecture or bit width(as I've experienced personally many times. Someone gets overenthusiastic and declares a function as size_t then goes ahead and uses it as int instead somewhere else, causing extremely hard-to-track bugs when parameters getting passed into the function get mangled...)