1

I am using the memcpy() function using the ARM EABI compiler. As I see in the file, the function is defined as

extern _ARMABI void *memcpy(void * __restrict /*s1*/,
                    const void * __restrict /*s2*/, size_t /*n*/)
                    __attribute__((__nonnull__(1,2)));
   /*
    * copies n characters from the object pointed to by s2 into the object
    * pointed to by s1. If copying takes place between objects that overlap,
    * the behaviour is undefined.
    * Returns: the value of s1.
    */

Please forgive my ignorance;as I am not much familiar with C and pointers in general.Could someone please detail me what does it mean by const void * and does those syntaxes (like __attribute etc.) need to be maintained while calling the function?

Thanks!

My implementation:

char mycharacter;
mycharacter = ROM_UARTCharGetNonBlocking(UART0_BASE);
memcpy(SRAM_BASE, mycharacter, size_t (mycharacter);
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Kashif Nawaz
  • 95
  • 1
  • 1
  • 13
  • Your code should not compile... – Deduplicator Jun 04 '14 at 20:19
  • 1
    See _just about any introductory C reference ever written_ for an explanation of C types (and just ignore the nonstandard compiler attributes) – Notlikethat Jun 04 '14 at 20:19
  • 1
    Why are you passing `memcpy` a *character* for its second parameter?! It needs to know what memory to copy from and to. And for what possible reason would you cast the character to a `size_t`?! (It sounds like you just have no idea how to use `memcpy` at all.) – David Schwartz Jun 04 '14 at 20:23
  • Ok...so how should I do that since i do not have the memory address of mycharacter? – Kashif Nawaz Jun 04 '14 at 20:25
  • 1
    The & operator lets you take the reference of a variable. Honestly if you have questions about the C language and syntax you should read up on that before asking questions on SO. – SeriousBusiness Jun 04 '14 at 20:30
  • ^ and by reference I really meant pointer or address – SeriousBusiness Jun 04 '14 at 20:33
  • @Kashif you will need to explain what you are trying to do , it's not clear from your code – M.M Jun 04 '14 at 21:44
  • @MattMcNabb: i am trying to write received values over UART to SRAM for a stellaris device. so the rxed values are put in say mycharacter which will then transfer it to SRAM. – Kashif Nawaz Jun 04 '14 at 22:49
  • `mycharacter` is a `char` - it can only hold one character at a time. Is this code intended to be called once for each character? NB. what does this function return if no characters are available? – M.M Jun 04 '14 at 22:51
  • this code is to be called everytime a character is available over the UART. so say a stream of 16 bytes is written over UART then these 16 bytes should be copied to the SRAM. this is what I am trying to do basically. – Kashif Nawaz Jun 05 '14 at 14:23

1 Answers1

1

The whole point of having a standard library is that you don't have to understand the implementation to use the function.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278
  • interesting...got ur point..however,as I said I am interested in using this function but getting errors...i will add the code which I am trying to use... – Kashif Nawaz Jun 04 '14 at 20:15
  • It seems like you have no idea how to use `memcpy` and should start by reading as much documentation on that function as you can find until you understand it. – David Schwartz Jun 04 '14 at 20:24
  • precisely yes, thats why I requested an explanation of the function...do you have any helpful links on this? – Kashif Nawaz Jun 04 '14 at 20:26
  • You can start with [this tutorial](http://www.tutorialspoint.com/c_standard_library/c_function_memcpy.htm). – David Schwartz Jun 04 '14 at 20:44
  • got it...i have made some progress now but stuck with 2 errors: uart_echo.c(95): error: #167: argument of type "int" is incompatible with parameter of type "void *restrict" – Kashif Nawaz Jun 04 '14 at 20:58
  • Why are you passing an `int` to `memcpy`? It wants addresses of chunks of memory. – David Schwartz Jun 06 '14 at 18:02