LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-24-2002, 12:52 PM   #1
lackluster
Member
 
Registered: Apr 2002
Location: D.C - USA
Distribution: slackware-current
Posts: 488

Rep: Reputation: 30
extern "C"


what does this do? i always see it in headers but don't understand...

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
 
Old 07-24-2002, 03:02 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Code between #ifdef __cplusplus and #endif (of course, the right #endif) is included when the header is included to a C++ file. It allows to have one header for C and C++.
 
Old 07-24-2002, 11:36 PM   #3
tyler_durden
Member
 
Registered: May 2001
Posts: 125

Rep: Reputation: 15
its needed so you can call a c function from cpp
 
Old 07-25-2002, 12:09 PM   #4
lackluster
Member
 
Registered: Apr 2002
Location: D.C - USA
Distribution: slackware-current
Posts: 488

Original Poster
Rep: Reputation: 30
Quote:
Code between #ifdef __cplusplus and #endif (of course, the right #endif) is included when the header is included to a C++ file. It allows to have one header for C and C++.
I assumed that, but why does there need to be extern "C" { } in a cpp header?

Quote:
its needed so you can call a c function from cpp
So C & C++ have different calling conventions??
 
Old 07-25-2002, 12:19 PM   #5
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Well, such ticks are needed, because C code will work in C++ program, but it won't the other way.
Note that the code you've found is the first part. There's also second one (because '{' needs a '}') at teh end.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Telling people to use "Google," to "RTFM," or "Use the search feature" Ausar General 77 03-21-2010 11:26 AM
"Xlib: extension "XFree86-DRI" missing on display ":0.0"." zaps Linux - Games 9 05-14-2007 03:07 PM
about extern "C" George2 Programming 6 09-03-2005 05:21 AM
extern "C" and static data type problem with g++ vtluu Red Hat 1 05-21-2004 10:45 AM
extern "C" and static data type problem with g++ vtluu Programming 2 04-28-2004 05:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration