?
Solved

What is the significance of "underscore prefix" in C

Posted on 1998-12-17
2
Medium Priority
?
825 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

764 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