> Grant Brown wrote:
>
>> Not much in C but 20 odd years in Delphi.
>>
>>
> You may want to look at mikropascal then...
>
http://www.mikroe.com/en/compilers/mikropascal/pic/ . I'm not trying
> to discourage you from learning C... but learning C on a PIC should be
> an interesting experience....
>
> One thing you need to keep in mind is that a PIC is EXTREMELY resource
> limited, and there are things you would normally do which will fail
> miserably on a PIC, just because of lack of code and or data space -
> even though the compiler is perfectly happy to let you try.
>
>> I think I was confusing "return" with "Result" in Delphi which does act
>> as a temporary variable until the function exits.
>>
>>
> Yep... That's why I caught the not a lot of C.... Anyone who's
> written much C would have caught this mistake :) ... But again, I've
> put a few semicolons in the wrong spot and couldn't figure out why it
> was always executing a block (or not).
>
>> so for the given function below is the way I have re-written it correct
>> - so in other words do I just
>>
>> * declare a local variable
>> * assign it a value
>> * then return the local variable
>>
>>
> For programming efficiency, I'd recommend using an early return instead
> of a scratch variable. There are two reasons: 1) the variable consumes
> memory and 2) the return helps short circuit code which may not need to
> need to be run. As I don't generally mix assembler with C, I'm not the
> best one to fix your particular code. In fact, the compilers I use all
> have functions and/or defs built in to do this, so you can just go
> directly after the bit value without resorting to writing your own
> function. That is, in say MikroC you say something like:
>
> PORTA=0x00;
> TRISA=0x00;
>
> if (PORTA.F1)
> {
> //do stuff here
> }
>
> Each C compiler has a little different way of doing this (like CCS C has
> functions, etc), but the idea is the same.
>
> Back on the return thing, what I am talking about would be something like:
>
> char yourfunction(char arg)
> {
> if (PORTA.F1) return 1;
> return 0;
> }
>
>
>