Xref: utzoo comp.lang.c++:1931 comp.lang.fortran:1487 Path: utzoo!utgpu!attcan!uunet!husc6!bloom-beacon!tut.cis.ohio-state.edu!osu-cis!att!cbnews!mjs From: mjs@cbnews.ATT.COM (martin.j.shannon) Newsgroups: comp.lang.c++,comp.lang.fortran Subject: Re: f77 and C++ w/ cin/cout: can it be done? Summary: main must be compiled by cfront Keywords: f77 C++ cin cout printf Message-ID: <2056@cbnews.ATT.COM> Date: 10 Nov 88 15:34:31 GMT References: <1118@rivm05.UUCP> Reply-To: mjs@cbnews.ATT.COM (martin.j.shannon) Organization: AT&T Bell Laboratories Lines: 65 In article <1118@rivm05.UUCP> ccea3@rivm05.UUCP (Adri Verhoef) writes: >- I have this fortran-file "m.f": > program main > call hello() > end >- and I have this C++-file "s.c": >#include >void hello_() >{ > STATEMENTS; >} >- The first time, I replace STATEMENTS by: > printf("Hello, %s\n", "world"); >$ a.out >Hello, world This works because there are no static constructors involved, so it doesn't matter which compiler generates main. >- The second time, I replace STATEMENTS by: > cout << "Hello, world\n"; >$ a.out >Bus error - core dumped Since the static constructor for cout was never invoked, there is no initialiaztion performed for the stream, and the constents of the class are garbage. >- The third time, I replace STATEMENTS by: > char str[128]; cin >> str; >$ a.out >Memory fault - core dumped Since the static constructor for cin was never invoked, there is no initialiaztion performed for the stream, and the constents of the class are garbage. In general: Cfront recognizes that main is the 1st executable statement in a source file, and appropriately replaces the user's main with code that arranges to make sure that static constructors are called. Thus, when mixing languages (not a particularly safe thing to do; though possible in many systems), the executable code generated for main must come from cfront. l i n e c o u n t e r f o o d . -- Marty Shannon; AT&T Bell Labs; Liberty Corner, NJ (Affiliation given for identification only.)