C memcpy in reverse

Aran Mulholland picture Aran Mulholland · Feb 11, 2010 · Viewed 22.5k times · Source

I am working with audio data. I'd like to play the sample file in reverse. The data is stored as unsigned ints and packed nice and tight. Is there a way to call memcpy that will copy in reverse order. i.e. if I had 1,2,3,4 stored in an array, could I call memcpy and magically reverse them so I get 4,3,2,1.

Answer

janm picture janm · Feb 11, 2010

No, memcpy won't do that backwards. If you're working in C, write a function to do it. If you're really working in C++ use std::reverse or std::reverse_copy.