🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #1442

Re: C++ compiler question

#1442
From: Jim Large
Date: Mon, 12 Oct 1992 17:14
54 lines
2364 bytes
In article <1992Oct9.003819.3434@bmers95.bnr.ca> hlam@bmerh136.bnr.ca (Hayward  
Lam) writes:
> 	I try to compile and link a c++ program. I type "cc++ program.c"

First of all, if you name your program "program.cc", then you can compile it  
with the command, "cc program.cc".  This will not fix your problem (which was)

> the linker returns the following:
> 	/bin/ld: Undefined symbols:
> 	_printf_FPCce

You are trying to call a C function (printf()) from a C++ module.  To do this,  
you must surround the declaration of printf() with 'extern "C" { }'.

Since all of the NeXT libraries were compiled as C, or Objective-C, you  
probably want to wrap the extern construct around all of your includes as  
shown:

extern "C"
{
#include <stdio.h>   /*contains declaration of printf()*/
#include <
    .
    .
    .>
}


Why?  Because C and C++ translate function names ==> symbol names differently.  


In C, names are translated by prefixing an underscore, so that 
	printf(const char *, ...)
becomes
        _printf


In C++, the translated names encode the argument types, and
	printf(const char *, ...)
becomes
        _printf_FPCce


This is what makes overloading possible.  If you declare
	printf(int, int);
C++ assumes that you are defining a DIFFERENT FUNCTION from the printf() that  
we all know and love.  Therefore it outputs a different symbol name, namely
	_printf_Fii

 
----------------+------------------+------------------------------------
     |\ /|      |  Jim Large       |  Visual Understanding Systems, Inc.
     | V |      |  jml@visus.com   |  2100 Wharton St.                  
   \_|   |__    |  (412)488-3600   |  Pittsburgh, PA  15203             
Technical Details
Message-ID: <1992Oct12.171402.15656@visus.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!eff!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!news.sei.cmu.edu!fs7.ece.cmu.edu!crabapple.srv.cs.cmu.edu!ibis.maya.com!menu!tuna!usenet
References: <1992Oct9.003819.3434@bmers95.bnr.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!eff!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!news.sei.cmu.edu!fs7.ece.cmu.edu!crabapple.srv.cs.cmu.edu!ibis.maya.com!menu!tuna!usenet
From: jml@visus.com (Jim Large)
Newsgroups: comp.sys.next.programmer
Subject: Re: C++ compiler question
Message-ID: <1992Oct12.171402.15656@visus.com>
Date: 12 Oct 92 17:14:02 GMT
References: <1992Oct9.003819.3434@bmers95.bnr.ca>
Sender: usenet@visus.com (Usenet news reciever)
Organization: Visual Understanding Systems, Pgh PA
Lines: 54
Nntp-Posting-Host: taco.visus.com