bachra04
asked on
Copy from dynamic array to static array
I have two question:
- First question:
I have an array statically allocated:
uint8_t dstArray[MAX_LENGTH];
uint8_t* pSrcArray = new uint8_t[100]; // 100 < MAX_LENGTH
// copied contents :
memcpy (dstArray, pSrcArray,100);
Is it safe to copy contents like that ? is there any more elegant way of doing that?
Second question:
I have String MyString that I have received ;
I need to use this method with an API that takes uint8_t* as a parameter:
myAPI( uint8_t* pArray);
Is it safe to cast the const char* to uint8_t ?
myAPI((uint8_t*)MyString .c_str());
Is there a better way of doing things.
- First question:
I have an array statically allocated:
uint8_t dstArray[MAX_LENGTH];
uint8_t* pSrcArray = new uint8_t[100]; // 100 < MAX_LENGTH
// copied contents :
memcpy (dstArray, pSrcArray,100);
Is it safe to copy contents like that ? is there any more elegant way of doing that?
Second question:
I have String MyString that I have received ;
I need to use this method with an API that takes uint8_t* as a parameter:
myAPI( uint8_t* pArray);
Is it safe to cast the const char* to uint8_t ?
myAPI((uint8_t*)MyString .c_str());
Is there a better way of doing things.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.