can I use some C++ feature to overload an existing C function with other function signatures?
For example, strcpy(char *, const char *) is a fine C function that already exists. Could I somehow add strcpy(char , __FlashStringHelper) that would execute different code?
(In general, this would provide a nice way for C++ to extend the functionality of C libraries. Perhaps usefully, perhaps confusingly (but surely no worse than overloading C operators!))
It looks like perhaps this "just works"?! How come it's not more widely used?
void strcpy(char *d, __FlashStringHelper* s) {
strcpy_P(d, (char*) s);
}
void loop() {
strcpy_P(foo, PSTR("reading"));
strcpy(foo, "testing");
strcpy(foo, F("writing"));
Produces:
void loop() {
strcpy_P(foo, PSTR("reading"));
61e: 60 e7 ldi r22, 0x70 ; 112
620: 70 e0 ldi r23, 0x00 ; 0
622: 82 e8 ldi r24, 0x82 ; 130
624: 91 e0 ldi r25, 0x01 ; 1
626: 0e 94 93 03 call 0x726 ; 0x726 <strcpy_P>
strcpy(foo, "testing");
62a: 65 e1 ldi r22, 0x15 ; 21
62c: 71 e0 ldi r23, 0x01 ; 1
62e: 82 e8 ldi r24, 0x82 ; 130
630: 91 e0 ldi r25, 0x01 ; 1
632: 0e 94 a5 03 call 0x74a ; 0x74a <strcpy>
}
char foo[16];
void strcpy(char *d, __FlashStringHelper* s) {
strcpy_P(d, (char*) s);
636: 68 e6 ldi r22, 0x68 ; 104
638: 70 e0 ldi r23, 0x00 ; 0
63a: 82 e8 ldi r24, 0x82 ; 130
63c: 91 e0 ldi r25, 0x01 ; 1
63e: 0e 94 93 03 call 0x726 ; 0x726 <strcpy_P>