Products > Programming

Noob: C port

(1/4) > >>

In my PIC C programming course I've come across a command that is not explained:

static bit button @ (unsigned) &PORTA*8+1;

What I think I know is:
the code is to assign the name "button" to RA1, static means that the value of "button" is to be retained between functions, unsigned means that the value of "button" has no mathematical sign and PORTA is port A(!)

I don't understand what these are doing:
bit, @, & (though I believe this is "logical .AND."), *8, 1 (I guess this refers to bit 1 of PORTA).

I'm not necessarily looking for descriptions (though all help is welcome) but where do I look to understand these things? I have Kernighan & Ritchie but this is not really a reference.


The @-sign is a compiler extension which allows you to specify the address of a global variable:

In this case it looks like a bit-variable is being defined at a specific bit-address - hence the PORTA*8+1 expression.

& is "address of"
(&& is "logical AND")

Read that as roughly:
Take the address of PORTA (&PORTA), multiply by 8 (*8), add 1 (+1) to get to the bit you want.

Additionally, '&' has two forms, unary and binary. Reminds me of another thread...

Cheers all.

So, why is it "*8"? Does each bit have an address?  :-//


[0] Message Index

[#] Next page

There was an error while thanking
Go to full version