home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18637 < prev    next >
Encoding:
Text File  |  1992-12-21  |  2.0 KB  |  48 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!ocsmd!ted
  3. From: ted@ocsmd.ocs.com (Ted Scott)
  4. Subject: Re: character pointers in funtion calls
  5. Message-ID: <BzGu96.7sI@ocsmd.ocs.com>
  6. Sender: news@ocsmd.ocs.com
  7. Organization: Online Computer Systems, Inc.
  8. X-Newsreader: Tin 1.1 PL5
  9. References: <1992Dec18.021709.16972@thunder.mcrcim.mcgill.edu>
  10. Date: Fri, 18 Dec 1992 17:36:40 GMT
  11. Lines: 35
  12.  
  13. der Mouse (mouse@thunder.mcrcim.mcgill.edu) wrote:
  14. : In article <BzD1w3.1z5@ocsmd.ocs.com>, ted@ocsmd.ocs.com  I wrote:
  15. : > Step 1: Get a good C primer and look at the memory sections, then
  16. : > walk through the code you present here and see if you can find some
  17. : > of these problems:
  18. : Hm, I think you might do well to follow this advice yourself in a
  19. : couple of cases.
  20. Only a couple?!? My I *am* _starting_ to learn this dialect. I don't give
  21. advice I won't follow, doesn't mean I remember everything. 
  22.  
  23. :>:   return (i);            <- (and implicitly free the memory on the stack
  24. :>                              where i had a happy albiet brief life) 
  25. :>                              returning the old value of i which may or may 
  26. :>                              not be overwritten when printf uses the stack. 
  27. :
  28. : No, no, no.  It is correct that the storage allocated to the variable i
  29. : goes away when f returns.  This *does not matter*, since no reference
  30. : to that storage survives.  The return statement returns the value that
  31. : was stored there, not, as you seem to think, a pointer to the storage
  32. : in question. 
  33. Yes, of course, must a been thinking of that other language.
  34. (a waist is a terrible thing to mind... or something).
  35.  
  36. <At the white board: returns are by value, not by reference...>
  37.  
  38. : That value is itself a pointer, but it points to a string
  39. : literal, which does *not* go away.
  40. And is usually read only storage. 
  41.  
  42. Thanks.
  43. --
  44.  
  45. -Ted (I been a bad boy, Abbot) Scott          
  46. tscott@ocsmd.ocs.com           I was told that I'm a P.C. person:
  47. (301) 601-2252                               Politically Challenged, that is.
  48.