Society of Robots - Robot Forum

Software => Software => Topic started by: arixrobotics on October 08, 2008, 03:17:32 AM

Title: underscores in C?
Post by: arixrobotics on October 08, 2008, 03:17:32 AM
Hi all,

Why is there an underscore before the U1RXIF register name in the following code snippets?

Code: [Select]
_U1RXIF=0; // Clear UART RX Interrupt Flag

And why are there many more underscores in the method declaration below?

Code: [Select]
void __attribute__((interrupt, no_auto_psv)) _IC1Interrupt(void)
I have no idea what the undescores do. Can anyone explain?

Title: Re: underscores in C?
Post by: ArcMan on October 08, 2008, 05:15:54 PM
Underscores preceding a variable name are, by convention, used for OS or programming package system calls.  Anyone can put as many underscores as they want wherever they want, it's just another character in the variable name.  But, like I said, convention.
Title: Re: underscores in C?
Post by: arixrobotics on October 09, 2008, 12:15:03 AM
But then why do they put an underscore before the word 'U1RXIF'? That word is a register name, which I dont think can be chaged by the programmer? And there was definately no declaration of a variable called '_U1RXIF' anywhere in the code.

This is for a dsPIC33FJ128MC802, and U1RXIF is the interrupt flag register of the UART's receiver, if these helps...

Title: Re: underscores in C?
Post by: pomprocker on October 14, 2008, 06:20:09 PM
those register names are just macros defined somewhere else for the compiler.