"...using the best programming practice..." yes sure
-
Porting some C code to one microcontroller to another I found this:
if((error == 0)
#ifdef SENSAR
|| (V_OK == 0))
#else
)
#endifThis work is unhealthy
-
Porting some C code to one microcontroller to another I found this:
if((error == 0)
#ifdef SENSAR
|| (V_OK == 0))
#else
)
#endifThis work is unhealthy
How else would you do it? Other than, of course, eliminating the
#else
by putting the right-parenthesis outside the#if
. -
How else would you do it? Other than, of course, eliminating the
#else
by putting the right-parenthesis outside the#if
.leaving V_OK = 0 whenever you don't define SEANSAR maybe. If I could I would put all the code here for you to see what I have to strugle every day. There are violations to every single "good programing practice", starting for the encapsulation, with a lot of variables and defines mixed in separated and "isolated" modules.
-
leaving V_OK = 0 whenever you don't define SEANSAR maybe. If I could I would put all the code here for you to see what I have to strugle every day. There are violations to every single "good programing practice", starting for the encapsulation, with a lot of variables and defines mixed in separated and "isolated" modules.
But this way eliminates a test when you don't have SENSAR; ergo it's FFFAAASSSTTTEEERRR... :cool: Why test something that's always true?
-
But this way eliminates a test when you don't have SENSAR; ergo it's FFFAAASSSTTTEEERRR... :cool: Why test something that's always true?
Maybe, but this things makes the code unclear and dificults the scalability. Anyway you are right in the fact that it is faster, innecesarily and almost insignificaly faster
-
Porting some C code to one microcontroller to another I found this:
if((error == 0)
#ifdef SENSAR
|| (V_OK == 0))
#else
)
#endifThis work is unhealthy
You're absolutely right. You ought to write it more concise:
if((error == 0)
#ifdef SENSAR
|| (V_OK == 0)
#endif
)Much cleaner now!
-
Porting some C code to one microcontroller to another I found this:
if((error == 0)
#ifdef SENSAR
|| (V_OK == 0))
#else
)
#endifThis work is unhealthy
-
Maybe, but this things makes the code unclear and dificults the scalability. Anyway you are right in the fact that it is faster, innecesarily and almost insignificaly faster
But when working with microcontrollers performance and memory management are important, aren't they? And many small things might lead to a noticeable gain in that.
-
I would have write it that way.
#ifdef SENSAR
if((error == 0) || (V_OK == 0))
#else
if((error == 0))
#endifPatrice “Everything should be made as simple as possible, but no simpler.” Albert Einstein
-
Porting some C code to one microcontroller to another I found this:
if((error == 0)
#ifdef SENSAR
|| (V_OK == 0))
#else
)
#endifThis work is unhealthy
-
But when working with microcontrollers performance and memory management are important, aren't they? And many small things might lead to a noticeable gain in that.
I was going to say that. Sometime had to do weird trick, that looked really ugly, just to save program memory :D (PIC16F84)
I do not fear of failure. I fear of giving up out of frustration.
-
I would have write it that way.
#ifdef SENSAR
if((error == 0) || (V_OK == 0))
#else
if((error == 0))
#endifPatrice “Everything should be made as simple as possible, but no simpler.” Albert Einstein
still has double parentheses on the 2nd case. That will slow the compiler massively :)
-
still has double parentheses on the 2nd case. That will slow the compiler massively :)