🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #504

C++ How do I print function addresses?

#504
From: Sam S. Wong
Date: Fri, 16 Oct 1992 20:00
56 lines
1646 bytes
Hi. I need some help.

I have class definition called ADC32.  This class has as a member, a public
function called display().

I have two data objects.  One is a variable of class ADC32 called slot1_adc,
the other is an array of 10 objects of class ADC32 called adc32.

The relevant code looks something like this:


//////////////////////
class ADC32 {
private:
  int id;
public:
  int display(void);
}

ADC32::display(void)
{
  cout << id;
}


ADC32 slot1_adc32, adc32[10];

main {
  cout << (int)&slot1_adc32.display;
  cout << (int)&adc32[1].display;
}
///////////////



My question is, is the last 2 lines correct for displaying the addresses of
those two functions?

If not, what would those 2 statements produce?


 
What I have found is that: (int)&slot1_adc32.display gives me the address of
ADC32::display() instead of a pointer to the address of ADC32::display().



I am trying to confirm that no space is allocated for an object's member 
functions.  In other words, while there is space allocated for slot1_adc32.id 
(4 bytes for an int), no space (for a function pointer) is allocated for 
slot1_adc32.display().  


what would be the result of:
"cout << (int)slot1_adc32.display;
 cout << (int)adc32[1].display;"    ?
Technical Details
Message-ID: <wong.719265648@sfu.ca>
Path: arc1-ca.pugleaf.net!sparky!uunet!destroyer!cs.ubc.ca!newsserver.sfu.ca!sfu.ca!wong

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!sparky!uunet!destroyer!cs.ubc.ca!newsserver.sfu.ca!sfu.ca!wong
From: wong@fraser.sfu.ca (Sam S. Wong)
Subject: C++ How do I print function addresses?
Message-ID: <wong.719265648@sfu.ca>
Sender: news@sfu.ca
Organization: Simon Fraser University, Burnaby, B.C., Canada
Date: Fri, 16 Oct 1992 20:00:48 GMT
Lines: 58