home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / next / programm / 5892 < prev    next >
Encoding:
Text File  |  1992-08-31  |  1.9 KB  |  67 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!nevada.edu!oliverm
  3. From: oliverm@nevada.edu (Moises Oliveira )
  4. Subject: Re: "bind"ing sockets, -ObjC, and memset....A puzzle
  5. Message-ID: <1992Aug31.192253.16733@nevada.edu>
  6. Summary: Programming through guesswork
  7. Sender: news@nevada.edu (USENET News System)
  8. Nntp-Posting-Host: helios.nevada.edu
  9. Organization: Organization? Ha, don't make me laugh
  10. References: <1992Aug26.043241.2355@relief.com> <1992Aug28.190230.2670@next.cambridge.ma.us> <17tieoINNsr5@news.aero.org>
  11. Date: Mon, 31 Aug 1992 19:22:53 GMT
  12. Lines: 53
  13.  
  14. In article <17tieoINNsr5@news.aero.org> strauss@Aero.org (Daryll Strauss) writes:
  15. >In article <1992Aug28.190230.2670@next.cambridge.ma.us>, simsong (Simson L. Garfinkel) writes:
  16. >|> Apparently, when you include the -ObjC flag, all stack variables are  
  17. >|> initialized to 0.
  18. >|> 
  19. >
  20. >It would be a really bad idea to rely on that "feature." You must clear
  21. >the sockaddr structure to use it. The C spec says that stack variables
  22. >have unknown values. I've need heard anything different in for ObjC. So
  23. >relying on the compiler to initialize variables for you is a disaster
  24. >waiting to happen.
  25.  
  26. It's especially a bad idea seeing as how it's plain out
  27. untrue!  The ObjC flag to the linker DOES NOT clear stack
  28. variables to 0.  When you pass ObjC to the linker, it pulls
  29. in a bunch of support for ObjC.  Because of this, in an
  30. itsy-bitsy tiny example program like the one posted, a
  31. large portion of the stack will end up filled with 0
  32. values.   
  33.  
  34.  
  35. But this will only remain true for the first function
  36. call.  To see what I mean, change the program a bit: 
  37.  
  38. int     foo(n)
  39. {
  40.         int     a,b;
  41.         int     c;
  42.  
  43.         printf("a=%d  b=%d  c=%d\n",a,b,c);
  44.         a = n;
  45.         c = n;
  46. }
  47.  
  48. main()
  49. {
  50.         int a,b,c;
  51.  
  52.     foo(17);
  53.     foo(13);
  54.     foo(11);
  55.     foo(7);
  56.     foo(5);
  57.     foo(3);
  58.     foo(2);
  59.     foo(1);
  60. }
  61.  
  62. The sample program and output that Simson Garfinkel
  63. posted works by mere coincidence. 
  64.  
  65.  
  66.  
  67.