What does the _ mean?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

What does the _ mean?

Jump to solution
1,401 Views
BobbyMK
Contributor I

Hello

I have CW 5.9.0 build 2404 and the DEMOQE128 board with the MCF51QE128.

I'm trying to undestand the  MCF51QE128.h file, I'd like to know what the _  means and does (see after union):

 

typedef union {
  byte Byte;
  struct {
    byte PTAD0       :1;                                       /* Port A Data Register Bit 0 */
    byte PTAD1       :1;                                       /* Port A Data Register Bit 1 */
    byte PTAD2       :1;                                       /* Port A Data Register Bit 2 */
    byte PTAD3       :1;                                       /* Port A Data Register Bit 3 */
    byte PTAD4       :1;                                       /* Port A Data Register Bit 4 */
    byte PTAD5       :1;                                       /* Port A Data Register Bit 5 */
    byte PTAD6       :1;                                       /* Port A Data Register Bit 6 */
    byte PTAD7       :1;                                       /* Port A Data Register Bit 7 */
  } Bits;
} PTADSTR;
extern volatile PTADSTR _PTAD @0xFFFF8000; 

 

#define PTAD                            _PTAD.Byte

 

Does an equivelant in gcc exsist?

Thank you for any help.

Message Edited by BobbyMK on 2009-09-24 06:16 PM
Labels (1)
0 Kudos
1 Solution
400 Views
pgo
Senior Contributor V

Dear BobbyMK,

 

The '_' is just part of a C language identifier.  C identifiers can start with a letter including the underscore.  

 

By convention, the identifiers starting with an underscore are reserved for use by the 'system'.  For example, many library routines use underscores internally.  User programs should not use underscores as the first letter.  This helps prevent clashes between names used by the system and in the user programs.

 

In the example you have quoted, the variable _PTAD is created to represent the the port as a bit field/union.  Various #define symbols are then created to conveniently access the port in various ways.  In this case the symbol PTAD can be used to access the port as a single 8-bit location.  Other symbols such as PTAD_BIT0 (or similar - from memory) can be used to access the individual bits within the bitfield and hence individual bits within the port.

 

The above approach is common in many C compilers for embedded systems.  The '@' symbol is the only Codewarrior C-compiler specific feature being used. (It also relies on detailed knowledge of how the compiler packs bit fields but the code is legal C otherwise).

 

I hope the above is clear!

 

bye

 

Message Edited by pgo on 2009-09-25 12:02 PM

View solution in original post

0 Kudos
2 Replies
401 Views
pgo
Senior Contributor V

Dear BobbyMK,

 

The '_' is just part of a C language identifier.  C identifiers can start with a letter including the underscore.  

 

By convention, the identifiers starting with an underscore are reserved for use by the 'system'.  For example, many library routines use underscores internally.  User programs should not use underscores as the first letter.  This helps prevent clashes between names used by the system and in the user programs.

 

In the example you have quoted, the variable _PTAD is created to represent the the port as a bit field/union.  Various #define symbols are then created to conveniently access the port in various ways.  In this case the symbol PTAD can be used to access the port as a single 8-bit location.  Other symbols such as PTAD_BIT0 (or similar - from memory) can be used to access the individual bits within the bitfield and hence individual bits within the port.

 

The above approach is common in many C compilers for embedded systems.  The '@' symbol is the only Codewarrior C-compiler specific feature being used. (It also relies on detailed knowledge of how the compiler packs bit fields but the code is legal C otherwise).

 

I hope the above is clear!

 

bye

 

Message Edited by pgo on 2009-09-25 12:02 PM
0 Kudos
400 Views
BobbyMK
Contributor I

Hello pgo,

I just wanted to thank you for the info it really helped me! Hope I'll be able to contribute one day on these forums! (as you can immagine I'm a real rookie!)

0 Kudos