Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!lll-winken!sundance!jac From: jac@gandalf.llnl.gov (James A. Crotinger) Newsgroups: comp.lang.c++ Subject: Re: bug with making C++ functions have C linkage ? Message-ID: Date: 18 Apr 91 03:30:23 GMT References: <1991Apr16.122905.23613@cs.nott.ac.uk> Sender: usenet@lll-winken.LLNL.GOV Lines: 44 Nntp-Posting-Host: sundance.llnl.gov I'm not certain, but I believe that in order to use streams, the main() program needs to be written in C++. The problem is that cout is a globally declared class which must be initialized before main() is called. This won't happen if the main() is written in C. For example, the following works fine on my Sun (using Sun C 1.0 and Sun C++ 2.0). ----------------------------------- // main.cc #include extern "C" void foo(void); extern "C" void bar(void); main() { bar(); } void foo() { cout << "Testing...\n"; } ----------------------------------- /* bar.c */ extern void foo(); void bar() { foo(); } ----------------------------------- Jim -- ----------------------------------------------------------------------------- James A. Crotinger Lawrence Livermore Natl Lab // The above views jac@moonshine.llnl.gov P.O. Box 808; L-630 \\ // are mine and are not (415) 422-0259 Livermore CA 94550 \\/ necessarily those of LLNL