Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

What is the significance of "underscore prefix" in C

Posted on 1998-12-17
2
Medium Priority
?
826 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

609 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