When using malloc and doing similar memory manipulation can I rely on sizeof( char ) being always 1?
For example I need to allocate memory for N elements of type
Using the sizeof(char) makes your code more readable and portable.
On x86, we all know that a character is 1 byte. But explicitly writing it down helps make your intentions clearer, which is always a good thing.
Also, what if your code gets put on some other platform where a character isn't 1 byte. What if a character was only 4 bits instead?
Agreed, it's not necessary, but it doesn't slow your run time down and it will pay off in that rare case you need to port your code to a different architecture.