Go Down

Topic: strncpy() causes reset (Read 5294 times) previous topic - next topic

blackm0k


I'll never understand why Microsoft invented a bunch of complex templates for casting, and why anyone uses them.


Just to set the record straight, the different cast types allow you to perform different types of casting as opposed to the C casting operation that strips all attributes from the cast variable. They also allow proper casting of polymorphic objects.

E.g. static_cast<char *>() will convert a (const void *) pointer to (const char *) pointer without stripping the const attribute. There is no way to do this with C casts unless you know that the original variable is const in every case to start with, and explicitly cast as (const char *).

PaulS

Quote
There is no way to do this with C casts unless you know that the original variable is const in every case to start with, and explicitly cast as (const char *).

If you don't know what the original type is, casting is hardly a good idea. The reason for most casts is to allow a function to accept a const array, when you KNOW that the function is not going to change the contents of the array, but the function doesn't explicitly guarantee that by using the const keyword.

In the case that OP is talking about, I can't figure out why ether.tcpReply() returns a const pointer. Why does it care if you want to point it to something else, or alter the contents that it points to?
The art of getting good answers lies in asking good questions.

Go Up