Electronics > Microcontrollers

Calling ASM functions in C

<< < (5/6) > >>

IanB:

--- Quote from: alm on April 29, 2012, 12:56:58 am ---results in f = 1.0, not 1.5 as you might expect
--- End quote ---

It's important not to expect that. The difference between integer and floating point division should perhaps be one of the first things you learn in programming class. I remember it was for me.

The reason why you can't expect a floating point division is that the left hand side of an assignment never influences the evaluation of what is on the right hand side. It's a golden rule.

alm:
A golden rule in C at least. Don't expect this to be universal across programming languages. One exception that comes to mind is Perl, which has the concept of the context of a function/operator. I'm not aware of anyone using Perl on 8-bit micros, though ;).

IanB:

--- Quote from: alm on April 29, 2012, 01:23:56 am ---A golden rule in C at least. Don't expect this to be universal across programming languages. One exception that comes to mind is Perl, which has the concept of the context of a function/operator. I'm not aware of anyone using Perl on 8-bit micros, though ;).

--- End quote ---

OK, you got me. I'm a Perl fan and capable Perl programmer.

But it is true in C family languages, and in Fortran. Maybe it's not a golden rule but a silver rule?

alm:
I think at the very least we can agree that it's important to know whether rule applies in your current programming language. Both the concept of context (eg. calling a function in list context Perl) and the lack of context (expecting a float division because the variable on the left hand side is a float) can easily cause confusion and seemingly obscure bugs.

TerminalJack505:
Wow!  I'm a big Perl fan as well.

Three of us right here.  What are odds?   :)

You actually don't see many Perl coders anymore.  Python seems to have stole its thunder.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod