Is Using 'sizeof(char)' When Dynamically Allocating A 'char' Redundant?

Viewed 1028

When dynamically allocating chars, I've always done it like this:

char *pCh = malloc(NUM_CHARS * sizeof(char));

I've recently been told, however, that using sizeof(char) is redundant and unnecessary because, "by definition, the size of a char is one byte," so I should/could write the above line like this:

char *pCh = malloc(NUM_CHARS);

My understanding is the size of a char depends on the native character set that is being used on the target computer. For example, if the native character set is ASCII, a char is one byte (8 bits), and if the native character set is UNICODE a char will necessarily require more bytes (> 8 bits).

To provide maximum portability, wouldn't it be necessary to use sizeof(char), as malloc simply allocates 8-bit bytes? Am I misunderstanding malloc and sizeof(char)?

6 Answers
Related