I know to some extent size_t and unsignedint are interchangable but size_t sometimes is preferable since it is more portable. But in the following simple test code, size_t does not work and I cannot figure out why.
It works for me (when I compile it as C++). As far as I know, size_t is a C++ member, why (and how) are you using it in C? If you wanted to do the same thing in C++, you would do something like this:
I don't know why I just did that, its obvious you are using C...
Anyway, I don't know what it is that is going on there. I'm pretty sure that size_t isn't part of C, so that might be what is going on for you.
I checked Wiki, it is said "The C language provides the separate types size_t and ptrdiff_t to represent memory-related quantities." So I think size_t is part of C.
Simply converting my C code to C++ will run successfully. So my gut feeling is the use of size_t in a C program, as you mentioned. In C++, using size_t seems okay.
I normally use for(size_t i = 0; i != 10; ++i) this type of coding and it (seems) works fine. Should I change to something like for(unsignedint i = 0; i != 10; ++i)? At least in C programming?