Solved

What is the significance of "underscore prefix" in C

Posted on 1998-12-17
2
814 Views
Last Modified: 2008-03-17
In many header files I am getting some of the functions and variables that are begining with '_'(an underscore)character, what it signifies?
For eg. In <conio.h> there are two functions getche() and _getche(), Please can U distinguish what are they. And to be more specific If I am using threads I can use either _beginthread() or just beginthread() but for my surprise both are working fine eventhough in <process.h> there is only one declaration i.e _beginthread().
Hoe it happens?
0
Comment
Question by:shivaki
2 Comments
 

Author Comment

by:shivaki
ID: 1255252
Edited text of question
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 0 total points
ID: 1255253
The ANSI/ISO standard for C specifies a set of library functions.  These don't have underscore.

Most compilers (including VC) offer Compiler specific extensions (VC) to the library

In old versions of Microsoft/Visual C the MS extensions didn't have a leading underscore.  It is now (I believe) an ANSI requirement that the names of non-ANSI library functions don't begin with a letter.  In any case old versions of MS Compiler didn't have leading underscore, new versions do.

When MS changed this, they didn't want to break tonnes of existing code written to their compiler.  Therefore they support use of non-underscored names (unless I think you enable strict ANSI compliance) for the compiler specific extensions.  Some medium-old versions of MS compiler require you to link oldnames.lib to enable the non-underscored names.

In summary I recommend you use the underscored names for all new code.  This is in better compliance with ANSI/ISO C standard, and makes it obvious to yourself (or other readers of your code) that you are using an MS extension, which could be important later if you port your code to another compiler/platform.

Finally the magic about the declarations is done using the .LIB files rather than the preprocessor.  Each .LIB is the pre-built library code (already contained) plus enough info for the compiler/linker to find each function by name.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now