Why does memset take an int as the second argument instead of a char, whereas wmemset takes a wchar_t instead of something like long or long long?
Why does memset take an int as the second argument instead of a char
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
memsetpredates (by quite a bit) the addition of function prototypes to C. Without a prototype, you can’t pass acharto a function — when/if you try, it’ll be promoted tointwhen you pass it, and what the function receives is anint.It’s also worth noting that in C, (but not in C++) a character literal like
'a'does not have typechar— it has typeint, so what you pass will usually start out as anintanyway. Essentially the only way for it to start as a char and get promoted is if you pass acharvariable.In theory,
memsetcould probably be modified so it receives acharinstead of anint, but there’s unlikely to be any benefit, and a pretty decent possibility of breaking some old code or other. With an unknown but potentially fairly high cost, and almost no chance of any real benefit, I’d say the chances of it being changed to receive acharfall right on the line between "slim" and "none".The value
memsetwrites into the destination is the value of its second argument converted to anunsigned char.