Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!usc!apple!motcsd!hpda!hpcuhb!hpindda!hardin From: hardin@hpindda.HP.COM (John Hardin) Newsgroups: comp.lang.c++ Subject: Re: C++ masquerading as C ... How? Message-ID: <6170012@hpindda.HP.COM> Date: 8 Jan 90 18:25:39 GMT References: <6170011@hpindda.HP.COM> Organization: HP Information Networks, Cupertino, CA Lines: 46 In answer to my question about how to make a C++ function masquerade as C, I received several replies all saying that I should use the 'extern "C"' construct. Though I was familiar with the use of this construct to tell C++ to use C linkage when linking with functions writen in C, I was not aware that it should be used to tell C++ to generate C function names to the linker for locally defined procedures. For those who asked me to post what I found out, I offer this simple example (which I used to prove to myself that it works): -----------------------> test.c <----------------------- #include main () { printf ("The length of 'abcd' is %d.\n", foo ("abcd")); } -----------------------> test2.C <----------------------- #include extern "C" int foo (char * str) { return (strlen (str)); } ---------------------------------------------------------- I created the executable 'test' as follows: CC -c test2.C cc -c test.c CC -o test test.o test2.o Indeed this did link properly and produced the output The length of 'abcd' is 4. To those who were kind enough to set me straight, thank you! John Hardin hardin%hpindgh@hplabs.hp.com ----------