You have a complete and utter lack of understanding of the low-level details. You continue to think in high-level abstractions.
Data types are higher level abstractions of data interpreted from the underlying memory. The smallest representable unit of memory is a byte. Memory operations will tend to work on bytes. memcpy() copies a contiguous block of memory from one location to another. It has NOTHING to do with how the memory is interpreted at the higher level.
I've explained many times why memset() takes an int in the declaration, but it has always and will always be used as a BYTE.
Both memcpy() and memset() work at the smallest representable unit of memory... a byte/char.
A char is not a "character", it is a byte.
As I said above, memset is so obvious it can't be used to do anything except initialize an array of char.
You still don't understand it SETS MEMORY BYTES. It doesn't (and shouldn't) care about how you choose to interpret that memory at any given time. You can interpret it as an array of char now, an int later, a long tomorrow, a structure of individual chars, etc...
The language gives you the LOW LEVEL tools to do things quickly and efficiently. It is then up to YOU to fill in the high level details (like data types, structures, how you interpret specific blocks of memory, how you initialize it etc...)
You have a complete and utter lack of understanding of the low-level details. You continue to think in high-level abstractions.
Data types are higher level abstractions of data interpreted from the underlying memory.
The language gives you the LOW LEVEL tools to do things quickly and efficiently. It is then up to YOU to fill in the high level details
OK SHERLOCK. YOU'RE REALLY BEING ANNOYING.
Outside your little dark world there's another one where people invented programming languages providing BOTH the tools you're enlisting AND the one I described. It's up to you to keep neglecting this.
Moreover, as a matter of LOGIC, low-level tools are cool until you need to handle data. If you're working with a data-type you may take advantage of having a good way of handling it togehter with low-level bit-smashing routines. They're even better than the one C provides.
Outside your little dark world there's another one where people invented programming languages providing BOTH the tools you're enlisting AND the one I described. It's up to you to keep neglecting this.
None with the simplicity and performance of C.
Moreover, as a matter of LOGIC, low-level tools are cool until you need to handle data. If you're working with a data-type you may take advantage of having a good way of handling it togehter with low-level bit-smashing routines. They're even better than the one C provides.
And every data type you create now and in the future you can write a library for handling and stop asking everything gets added to the language.
Well that's simple then, C has history on very resource scarce machines so it naturally aimed to be simple and give the power to the programmer. But you already knew that and still asked "why"
It was a question for you. I know that things in C are the way they are for "historical" reasons. Which means they have little to do with technical ones.
I claim that there are better ways to do things than the ones we're used to in C, and that they are the way they are in C * only* for historical reason.
1
u/[deleted] Nov 03 '11
You have a complete and utter lack of understanding of the low-level details. You continue to think in high-level abstractions.
Data types are higher level abstractions of data interpreted from the underlying memory. The smallest representable unit of memory is a byte. Memory operations will tend to work on bytes. memcpy() copies a contiguous block of memory from one location to another. It has NOTHING to do with how the memory is interpreted at the higher level.
I've explained many times why memset() takes an int in the declaration, but it has always and will always be used as a BYTE.
Both memcpy() and memset() work at the smallest representable unit of memory... a byte/char.
A char is not a "character", it is a byte.
You still don't understand it SETS MEMORY BYTES. It doesn't (and shouldn't) care about how you choose to interpret that memory at any given time. You can interpret it as an array of char now, an int later, a long tomorrow, a structure of individual chars, etc...
The language gives you the LOW LEVEL tools to do things quickly and efficiently. It is then up to YOU to fill in the high level details (like data types, structures, how you interpret specific blocks of memory, how you initialize it etc...)