What is the difference between strncmp_P and strncmp_PF on Arduino? I understand strncmp_F, but what is purpose of strncmp_PF?
Asked
Active
Viewed 1,391 times
1 Answers
2
There are two address spaces on Arduino: SRAM and Program memory (Flash).
You can refer to program memory using a normal "near" pointer, or a special "far" pointer to access more memory than is normally possible (e.g. near pointers can only access 64KB of program memory on a 16-bit CPU).
strncmp_P
and strncmp_PF
both compare with strings in program memory (as opposed to strncmp
, which compares two strings from SRAM), but strncmp_PF
takes a far pointer while strncmp_P
takes a normal near pointer. That's the only difference.

nneonneo
- 171,345
- 36
- 312
- 383
-
So on Arduino Mega with 256KB flash must use strncmp_PF and not strncmp_P? – BrankoH Aug 13 '14 at 14:38
-
@BrankoH: presumably, yes. – nneonneo Aug 13 '14 at 16:02
-
@BrankoH That depends where your data sits. Usually, on ATXmega the data in the code segment comes before the code. If you have 256kB flash, but only up to 64 kB of constant data, you don't need far data pointers. Only if the data exceeds this barrier, you need to take care. – glglgl Jun 06 '16 at 11:27