I want to pass in a hardcoded char array as the source
parameter to memcpy ... Something like this:
memcpy(dest, {0xE3,0x83,0xA2,0xA4,0xCB} ,5);
This compiled with clang gives the following error:
cccc.c:28:14: error: expected expression
If i modify it to be (see the extra parenthesis ):
memcpy(dest,({0xAB,0x13,0xF9,0x93,0xB5}),5);
the error given by clang is:
cccc.c:26:14: warning: incompatible integer to pointer
conversion passing 'int' to parameter of
type 'const void *' [-Wint-conversion]
cccc.c:28:40: error: expected ';' after expression
memcpy(c+110,({0xAB,0x13,0xF9,0x93,0xB5}),5);
So, the question:
How do I pass in a hardcoded array as the source parameter of memcpy
(http://www.cplusplus.com/reference/cstring/memcpy/)
I have tried:
(void*)(&{0xAB,0x13,0xF9,0x93,0xB5}[0]) - syntax error
{0xAB,0x13,0xF9,0x93,0xB5} - syntax error
({0xAB,0x13,0xF9,0x93,0xB5}) - see above
(char[])({0xE3,0x83,0xA2,0xA4,0xCB}) - error: cast to incomplete type 'char []' (clang)
and some more insane combinations I'm shamed to write here ...
Please remember: I do NOT want to create a new variable to hold the array.
question from:
https://stackoverflow.com/questions/35745385/c-hardcoded-array-as-memcpy-parameter