🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #846

Re: Problems #including K&R function prototypes from C++

#846
From: Shekar Ramanathan
Date: Mon, 27 Nov 1995 21:23
60 lines
1851 bytes
Max Welton (maxw@lmsc.lockheed.com) wrote:
[snip]
> We have found nothing in the gcc/g++ man-pages that
> addresses this problem and are not in a position to
> edit the third-party header files. We would very much
> like to use g++ (for various reasons). Have I overlooked
> something obvious?

Yes.  You should have only function *prototypes*, not function definitions,
inside extern "C" (see FAQ).

> $ cat foo.h
> #ifndef foo_h
> #define foo_h
> int foo(boo)
>    int boo;
> {
>    return boo;   
> }
> #endif

> $ cat main.C
> #include <iostream.h>
> extern "C" {
> #include "foo.h"
> }
> int main()
> {
>    cout << "Hello" << endl;
>    return foo(0);
> }

What you should do is have another file called foo.c and compile it using
a K&R C compiler.  In main.C, you should just include a prototype declaration
for foo and finally link them together.

foo.c
int foo(boo)
    int boo;
{
   return boo;   
}

main.C:

extern "C"{
	int foo();
}
int main()
{ cout << foo(0) << endl; }


Shekar

--
---------------------------------------------------------------------
Shekar Ramanathan              |   mailto:shekar@CS.MsState.edu
Department of Computer Science |   http://www.cs.msstate.edu/~shekar
Mississippi State University   |
---------------------------------------------------------------------
Technical Details
Message-ID: <49da94$kev@NNTP.MsState.Edu>
Path: arc1-ca.pugleaf.net!gizmo.cs.msstate.edu!shekar
References: <49d4ic$ooq@butch.lmsc.lockheed.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!gizmo.cs.msstate.edu!shekar
From: shekar@gizmo.cs.msstate.edu (Shekar Ramanathan)
Newsgroups: gnu.g++.help,comp.lang.c++
Subject: Re: Problems #including K&R function prototypes from C++
Followup-To: gnu.g++.help,comp.lang.c++
Date: 27 Nov 1995 21:23:48 GMT
Organization: Mississippi State University
Message-ID: <49da94$kev@NNTP.MsState.Edu>
References: <49d4ic$ooq@butch.lmsc.lockheed.com>
NNTP-Posting-Host: gizmo.cs.msstate.edu
X-Newsreader: TIN [version 1.2 PL0]