I've got two bits of code that should do the same thing, but one of them works and one doesn't.
This version works....
uint16_t funcA( uint16_t n )
{
uint16_t z=-n;
return z & 7;
}
This version should do exactly the same....
uint16_t funcB( uint16_t n )
{
return –n & 7;
}
But instead I get this compiler error.....
Example1:168: error: stray '' in program
Example1.cpp: In function 'uint16_t f4(uint16_t)':
Example1:168: error: 'u2013n' was not declared in this scope
Any idea why the first works but the 2nd doesn't?
BTW, the 2nd non-functioning example is the original code that seems to work on a different implementation of C. The 1st example does do what I need it to do, so this question is for information only, I already have a viable solution.
How are you using them because this works just fine.
(IDE 1.5.7)
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println(funcA(50));
Serial.println(funcB(50));
}
void loop() {
// put your main code here, to run repeatedly:
}
uint16_t funcB( uint16_t n )
{
return -n & 7;
}
uint16_t funcA( uint16_t n )
{
uint16_t z=-n;
return z & 7;
}
sketch_dec16a:2: error: stray '\' in program
sketch_dec16a.cpp: In function 'uint16_t f4(uint16_t)':
sketch_dec16a:2: error: 'u2013n' was not declared in this scope
Thank you. I have always want to achieve the impossible, I'm very proud!
No setup() function ?
correct
No loop() function ?
correct
Not even main() ?
correct again!
In an effort to dot the i's and cross the t's I have added a loop() and setup() and have attempted to attach a screen dump. The error message remains the same.
Try downloading a more current version and it compiles just fine.
Yes - I've just discovered that myself.
Unfortunately the later version of the the IDE incorporate some changes in the way PROGMEM is handled. The result is that several of my older projects only work on version 1.0, hence my reluctance to do a permanent upgrade.
What are you trying to accomplish?
I ask these questions so we don't find we are wasting our time.
Both functions do the same thing, they return the compliment to the next multiple of 8. Since one of them works, I do already have a solution. As stated in my original post, the problem was posted for information only, it now seems that the problem was to do with the IDE/compiler, rather than a programming issue.