user1160866
user1160866

Reputation: 159

cast to pointer from integer of different size [-Wint-to-pointer-cast]

Well, I have to revive a question that was answered here before. I've made some changes for other reasons and now I have a problem again. Here is the relevant details:

volatile char RxBuffer1[NEMA_BUFFER_LENGTH];
uint32_t NEMA_TypeStart;
char NEMA_Type[10];
uint32_t len;
...

memcpy(NEMA_Type,(const char*)RxBuffer1[NEMA_TypeStart], len);

With the cast I get the error shown in the subject line. Without the cast I get:

passing argument 2 of 'memcpy' makes pointer from integer without a cast

Note the same thing happens if I use strncpy instead. So I'm stumped. I thought I understood that memcpy uses void*. What am I doing wrong?

Upvotes: 0

Views: 2751

Answers (2)

BillRobertson42
BillRobertson42

Reputation: 12883

Its been awhile, but I think you need to say this instead...

memcpy(NEMA_Type, &RxBuffer1[NEMA_TypeStart], len);

You could also say...

memcpy(NEMA_Type, RxBuffer1 + NEMA_TypeStart, len);

Upvotes: 1

David Schwartz
David Schwartz

Reputation: 182753

You need to pass addresses to memcpy. I would assume you want:

memcpy(NEMA_Type,(const char*) &RxBuffer1[NEMA_TypeStart], len);

Upvotes: 1

Related Questions