home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #23 / NN_1992_23.iso / spool / gnu / gcc / help / 2339 < prev    next >
Encoding:
Text File  |  1992-10-16  |  1.5 KB  |  69 lines

  1. Newsgroups: gnu.gcc.help
  2. Path: sparky!uunet!destroyer!cs.ubc.ca!newsserver.sfu.ca!sfu.ca!wong
  3. From: wong@fraser.sfu.ca (Sam S. Wong)
  4. Subject: C++ How do I print function addresses?
  5. Message-ID: <wong.719265648@sfu.ca>
  6. Sender: news@sfu.ca
  7. Organization: Simon Fraser University, Burnaby, B.C., Canada
  8. Date: Fri, 16 Oct 1992 20:00:48 GMT
  9. Lines: 58
  10.  
  11. Hi. I need some help.
  12.  
  13. I have class definition called ADC32.  This class has as a member, a public
  14. function called display().
  15.  
  16. I have two data objects.  One is a variable of class ADC32 called slot1_adc,
  17. the other is an array of 10 objects of class ADC32 called adc32.
  18.  
  19. The relevant code looks something like this:
  20.  
  21.  
  22. //////////////////////
  23. class ADC32 {
  24. private:
  25.   int id;
  26. public:
  27.   int display(void);
  28. }
  29.  
  30. ADC32::display(void)
  31. {
  32.   cout << id;
  33. }
  34.  
  35.  
  36. ADC32 slot1_adc32, adc32[10];
  37.  
  38. main {
  39.   cout << (int)&slot1_adc32.display;
  40.   cout << (int)&adc32[1].display;
  41. }
  42. ///////////////
  43.  
  44.  
  45.  
  46. My question is, is the last 2 lines correct for displaying the addresses of
  47. those two functions?
  48.  
  49. If not, what would those 2 statements produce?
  50.  
  51.  
  52.  
  53. What I have found is that: (int)&slot1_adc32.display gives me the address of
  54. ADC32::display() instead of a pointer to the address of ADC32::display().
  55.  
  56.  
  57.  
  58. I am trying to confirm that no space is allocated for an object's member 
  59. functions.  In other words, while there is space allocated for slot1_adc32.id 
  60. (4 bytes for an int), no space (for a function pointer) is allocated for 
  61. slot1_adc32.display().  
  62.  
  63.  
  64. what would be the result of:
  65. "cout << (int)slot1_adc32.display;
  66.  cout << (int)adc32[1].display;"    ?
  67.  
  68.  
  69.