home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / hp / 12876 < prev    next >
Encoding:
Internet Message Format  |  1992-11-13  |  2.3 KB

  1. From: curtw@hpcuhe.cup.hp.com (Curt Wohlgemuth)
  2. Date: Fri, 13 Nov 1992 02:36:01 GMT
  3. Subject: Re: Casting from loose to strict alignment - what does this mean?
  4. Message-ID: <31480282@hpcuhe.cup.hp.com>
  5. Organization: Hewlett Packard, Cupertino
  6. Path: sparky!uunet!zaphod.mps.ohio-state.edu!wupost!sdd.hp.com!hpscit.sc.hp.com!scd.hp.com!hpscdm!cupnews0.cup.hp.com!hppad.waterloo.hp.com!hppad!hpfcso!hpcss01!hpcuhe!curtw
  7. Newsgroups: comp.sys.hp
  8. References: <1992Nov12.075922.1442@codex.oz.au>
  9. Lines: 48
  10.  
  11. bpja@codex.com.au (Brett Adam) writes:
  12.  
  13. > Ok, I'm beginning to clutch at straws but my memory problems have me somewhat 
  14. > annoyed. The following applies to HP 700 series.
  15. > With all warnings on (+w1) using cc in ansi mode, I'm getting occasional
  16. > warnings of the following nature:
  17. > cc: "ni_glue.c", line 767: warning 530: Casting from loose to strict alignment.
  18. > Does anyone have a precise definition of what this means/indicates? I'm new to
  19. > the HP environment and am unsure as to how important this may be in the scheme
  20. > of things.
  21.  
  22. You'll get this if you, say, take a pointer to char (with only 1-byte,
  23. or "loose" alignment) and cast it to a pointer to int (with 4-byte, or
  24. "strict" alignment).  The compiler is only trying to let you know of a
  25. possible problem if you subsequently dereference the pointer as if it
  26. were an "int *", and it doesn't point to a 4-byte aligned object.  E.g.,
  27. this program will dump core at run time:
  28.  
  29. -------------------------------------------------------------
  30. char ar[] = "hi mom";
  31.  
  32. main()
  33. {
  34.    int *pi = (int *) &ar[1];
  35.    int i = *pi;   /* This will cause a bus error */
  36. }
  37. -------------------------------------------------------------
  38.  
  39. With no options to the C compiler, this will produce no diagnostic at
  40. compile time; with "+w1" it will tell you
  41.  
  42. cc:  "t.c", line 5:  warning 530:  Casting from loose to strict alignment.
  43.  
  44. You (generically) as a competent software developer may know exactly
  45. what you're doing with this cast (i.e., either you're not going to
  46. dereference the pointer, or you know yourself that the operand of the
  47. cast operation is suitably aligned), but the compiler is trying to help
  48. you with a potential problem.
  49.  
  50. This may well not apply to your memory problems, but I hope this helps.
  51.  
  52. Curt Wohlgemuth
  53. HP California Language Lab
  54.  
  55. Official disclaimers apply to the above info, as usual...
  56.