home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / coherent / 3771 < prev    next >
Encoding:
Text File  |  1992-08-17  |  2.3 KB  |  59 lines

  1. Newsgroups: comp.os.coherent
  2. Path: sparky!uunet!utcsri!torn!maccs!mcshub!csx.cciw.ca!hcp
  3. From: hcp@csx.cciw.ca (H.C. Pulley)
  4. Subject: Re: Bug in Coherent 4.0 Compiler
  5. Organization: Canada Centre for Inland Waters
  6. Distribution: usa
  7. Date: Mon, 17 Aug 1992 19:19:25 GMT
  8. Message-ID: <1992Aug17.191925.3122@csx.cciw.ca>
  9. References: <1992Aug17.133350.7012@miles.com> <SJE.92Aug17114818@xylos.ma30.bull.com>
  10. Lines: 47
  11.  
  12. In article <SJE.92Aug17114818@xylos.ma30.bull.com> sje@xylos.ma30.bull.com writes:
  13. >> -------------------------------------- cut here ------------------------
  14. >> char *string = "Hello World\n";
  15. >>
  16. >> main()
  17. >> {
  18. >> char **pp;
  19. >>
  20. >> *pp = string;
  21. >> printf("%s", *pp);
  22. >> }
  23. >> -------------------------------------- and here ------------------------
  24. >>
  25. >> This program bombs my system and dumps the core. I have tried this 
  26. >> on other UNIX systems and even dos and it works just fine...
  27.  
  28. Check again.  Under EP/IX here the program does not dump core but no message
  29. is printed.  Under ULTRIX, the program causes a Segmentation Violation and 
  30. dumps a big core.
  31.  
  32. >> How can this get corrected? Do we have to wait until 4.1????
  33. >
  34. >It's a bug in your code.  The value of variable pp is undefined at the
  35. >time it is dereferenced in the statement "*pp = string".  That
  36. >assignment is either trashing four bytes somewhere or trying to write
  37. >outside the data segment.  It is not a problem with Coherent.
  38.  
  39. Since DOS doesn't use any memory protection, this problem will only show up
  40. if pp points to something crucial.  I still doubt, however, that the message
  41. will be printed correctly, since *pp is not pointing to the right place.
  42.  
  43. Your problem lies with *string being a 'pointer to char' and **pp being a 
  44. 'pointer to pointer to char'.  The line
  45. *pp=string
  46. is attempting to set the area of memory pointed to by pp to the value string,
  47. which is a memory location.  Since pp is uninitialized, as pointed out by
  48. Steve, you may trash memory by assigning it a value.
  49.  
  50. I don't want to sound insulting here, but that is the wierdest 'Hello, World'
  51. program I have ever seen. 
  52.  
  53. Harry
  54. -- 
  55.          hcp@csx.cciw.ca           | This message    | It takes all kinds,
  56.    hcpiv@grumpy.cis.uoguelph.ca    | released to the | and to each his own.
  57. -----------------------------------| PUBLIC DOMAIN.  | This thought in mind,
  58.  Stay away from the DOS side Luke! |                 | I walk alone.
  59.