🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#845
From: Max Welton
Date: Mon, 27 Nov 1995 19:46
50 lines
1749 bytes
I'm attempting to use g++ 2.7.1 with a combination of 
our own C++ and various vendor's C. When a #included
header contains a K&R style function prototype, g++ 
is unable to parse it (see below). The HP C++ cfront
compiler handles the same code with a warning (again, 
see below).

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?

$ 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);
}

$ g++ -c main.C
main.C:4: `boo' was not declared in this scope
main.C:5: parse error before `int'
main.C:6: parse error before `{'

Compilation exited abnormally with code 1 at Mon Nov 27 11:26:24

CC -c main.C
CC: "main.C", line 4: warning: old style definition of foo() (anachronism)
(1386)

Compilation finished at Mon Nov 27 11:35:38
--
Max Welton, CMST (Coordinator of Many Small Things)
   maxw@lmsc.lockheed.com
   maxw@ix.netcom.com
Technical Details
Message-ID: <49d4ic$ooq@butch.lmsc.lockheed.com>
Path: arc1-ca.pugleaf.net!newsjunkie.ans.net!butch!news

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newsjunkie.ans.net!butch!news
From: Max Welton <maxw@lmsc.lockheed.com>
Newsgroups: gnu.g++.help,comp.lang.c++
Subject: Problems #including K&R function prototypes from C++
Date: 27 Nov 1995 19:46:20 GMT
Organization: 42-10
Message-ID: <49d4ic$ooq@butch.lmsc.lockheed.com>
NNTP-Posting-Host: bismark.ssd.lmsc.lockheed.com
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.05 9000/715)
X-URL: news:gnu.g++.help