Question Details

No question body available.

Tags

c embedded

Answers (1)

April 9, 2026 Score: 0 Rep: 153,089 Quality: Medium Completeness: 80%

There are multiple issues in the posted code:

  • the destination address defined as uint8t address only has 8 bits. This is seems unlikely so you might want to check this prototype.
  • given that mydata16b is volatile, it will be read twice to initialize the array myArray as uint8t myArray[3] = {mydata8b, mydata16b, mydata16b >> 8}; You might want to use an intermediary local variable to only read the global variable once, hence ensure that the values of the high and lo bytes are consistent.
  • if the SerWrite handler just copies the pointer to static memory and handles the data asynchronously, you basically have no safe way to determine when to free the array or reuse it. You could allocate memory for this and worry about freeing later or use a static array if you can ensure MyWriteFun is not called again until the data has been sent. Such an API is very error prone.