> Horse and saddle to that guy who find what is wrong in below code:
> unsigned int oct2int(const char* oct){
> unsigned int ret = 0;
> int i,j=0,k,length = strlen(oct);
>
>     for(i=length-1;i >= 0;i--){
> if((k=(oct[i]-'0')) > 0)    ret += 1<<(3*j) * k;//8 = 2^3
> j++;
>     }
> return ret;
> }


Did you learn to program at http://www.de.ioccc.org/main.html ?  What's
wrong with the code is that is is illegable - in my book, that makes the
code incorrect regardless of what happens when you try to compile and run
it.  It's also horribly inefficient (you are scanning the string twice,
using an unnecessary multiply, and using an unnecessary variable shift) -
that's just not how you write code for embedded systems.  I'd post an
example implementation, but Bill beat me to it.

And if you want to post generated assembly (something that is often useful
to aid debugging), avoid flags that do loop unrolling or inlining, since
they generate far more code to look through, and include the flags used.

Note - it is possible that you've hit a bug in the compiler here somewhere,
since you should not need to explicitly re-enable the interrupts.  Can you
cut down the code to a minimum that still displays the interrupt problem,
and then post the code, generated assembly, and information about the
compiler version and compile flags?



Reply via email to