Hi,
I tried to create my own function but fell on this problem:
OTAWebUpdaterWebPage3.ino:319:19: error: call to non-constexpr function ‘int mystrcmp(char*, char*)’
char toswitch[] = {"Page disponible pour 2 heures entre 16 et 18:00 heures.\nDonc peut être consultée jusqu'à 19:00 heures"};
//const int ii = (const)strlen(toswitch);
RTC_DATA_ATTR char awakin[102];
int mystrcmp(char *s, char *t)
{
for (; *s == *t; s++, t++)
if (*s == '\0')
return 0;
return (*s - *t);
}
Regards,
JPD
Hi,
I red a bit on it and I wonder how I could force the compiler not to consider it a constexp function.
By adding a useless analogRead() or else tasks to do.
Regards,
JPDaviau
Your function accepts a volatile pointer to a character. There is an excellent response to a Stack Overflow question at https://arduino.stackexchange.com/questions/37718/how-to-pass-a-string-pointer-to-a-function which I’ll reproduce below:
You can pass parameters to functions by reference by value or ‘by pointers’.
Passing a parameter by value means that the function has a separate copy of the parameter so this is more expensive in terms of memory. It also means that any changes you make to the parameter inside the function are not reflected outside the function, they are two separate variables after all.
Passing by reference in C/C++ is done by adding a & after the parameter’s type, (int& byRef)
. This means that you are using the same variable inside and outside of the function. If you want to prevent the function changing the value then you set the parameter to be a constant reference. const int& constByRef
There is a third method which is passing a pointer. This is very useful for parameters that are a few bytes in size, i.e. strings and structures char* ptr
. When you pass a pointer it is passed by value, you can modify the pointer or the data it points to. Since a pointer is usually only the word size of the processor it is only as expensive as passing an int parameter.
When you pass a const char* cPtr
you can not modify the value of the pointer, but you can modify the value of the data pointed to. This type of parameter will let you pass in string literals.
To make you code cleared always write functions to accept constant parameters. If the parameter is larger than a word pass it by reference unless its an array (including char*) in which case pass it by pointer. If in doubt it should be a constant reference to start with. Sometimes embedded constraints affect these rules.
Also, take a look at this article.