Source Code for memcpy()

C

Chris Dollin

smnoff said:
How does one get the source code for memcpy()?

Why does one want the source code for memcpy?

[Not that there aren't reasons, but I'm curious as to what they are.]

Note that there is no "the" source code for memcpy. There will be
many sources: some cunningly optimised for a particular environment,
some written to make the intended effect clear; some written in ISO C,
some written in GNU C, some written in assembler ...

Was the Vax C runtime library written in C or Bliss or whatever?
 
T

Tim Prince

Richard said:
Suman said:


A very portable implementation.

I'd expect machine-specific implementations to box a bit more cleverly,
though - e.g. copying a word at a time rather than a byte as far as
possible, or using dedicated machine instructions where that's relevant.
Some even check for specific CPU hardware variants, to work around
performance issues with certain instruction sequences. Implementations
for SSE surely will look for aligned runs which can be dealt with by
16-byte loads and stores.
 
M

Malcolm

Richard Heathfield said:
Suman said:

A very portable implementation.
Though not strictly conforming.
Arbitrary data must be cast to unsigned char, not plain char.
 
M

Malcolm

smnoff said:
How does one get the source code for memcpy()?
The string library functions are generally pretty easy to implement with
reasonable efficiency.
memcpy() can be just a bte-copying loop, for instnace.

They are standard library functions for convenience, and because a clever
machine-specific implementation can take advantage of 32-bit copies and the
like. Sometimes the function call might even be inlined by the compiler.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,969
Members
47,524
Latest member
ecomwebdesign

Latest Threads

Top