Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Per Westermark
06/11/12 07:37
Read: 571 times
Sweden


 
Msg Score: +1
 +1 Informative
#187662 - Underscore
Responding to: Hal Albach's previous message
The C language per default adds an underscore to all symbols with external linkage.

So the function main() in the application will get the external linkage name _main.

Internal helper functions in the C runtime library uses a '_' prefix to their names, so they do not collide with end-user symbol names. The compiler will then too add a leading underscore, so a CRTL function _init_crtl() will get the external linkage name __init_crtl.

Assembler files do not add any underscore prefix.

In the end, this means that there are basically three different "name spaces" available.

One without leading underscores, used by assembler code.
One with a single leading underscore, used by end-user C code.
One with two leading underscores, used internally by the CRTL.

When mixing assembler and C, it is important to know that the assembler code must always explicitly add a '_' prefix when interacting with C symbols.

List of 5 messages in thread
TopicAuthorDate
SiLabs C8051F120 & SDCC Startup code      Hal Albach      06/10/12 19:31      
   mind the underscore        Maarten Brock      06/11/12 03:39      
      Thank you, Maarten!      Hal Albach      06/11/12 06:27      
         Underscore        Per Westermark      06/11/12 07:37      
            Now it makes sense      Hal Albach      06/11/12 08:36      

Back to Subject List