home *** CD-ROM | disk | FTP | other *** search
- From: curtw@hpcuhe.cup.hp.com (Curt Wohlgemuth)
- Date: Fri, 13 Nov 1992 02:36:01 GMT
- Subject: Re: Casting from loose to strict alignment - what does this mean?
- Message-ID: <31480282@hpcuhe.cup.hp.com>
- Organization: Hewlett Packard, Cupertino
- 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
- Newsgroups: comp.sys.hp
- References: <1992Nov12.075922.1442@codex.oz.au>
- Lines: 48
-
- bpja@codex.com.au (Brett Adam) writes:
-
- > Ok, I'm beginning to clutch at straws but my memory problems have me somewhat
- > annoyed. The following applies to HP 700 series.
- >
- > With all warnings on (+w1) using cc in ansi mode, I'm getting occasional
- > warnings of the following nature:
- >
- > cc: "ni_glue.c", line 767: warning 530: Casting from loose to strict alignment.
- >
- > Does anyone have a precise definition of what this means/indicates? I'm new to
- > the HP environment and am unsure as to how important this may be in the scheme
- > of things.
-
- You'll get this if you, say, take a pointer to char (with only 1-byte,
- or "loose" alignment) and cast it to a pointer to int (with 4-byte, or
- "strict" alignment). The compiler is only trying to let you know of a
- possible problem if you subsequently dereference the pointer as if it
- were an "int *", and it doesn't point to a 4-byte aligned object. E.g.,
- this program will dump core at run time:
-
- -------------------------------------------------------------
- char ar[] = "hi mom";
-
- main()
- {
- int *pi = (int *) &ar[1];
- int i = *pi; /* This will cause a bus error */
- }
- -------------------------------------------------------------
-
- With no options to the C compiler, this will produce no diagnostic at
- compile time; with "+w1" it will tell you
-
- cc: "t.c", line 5: warning 530: Casting from loose to strict alignment.
-
- You (generically) as a competent software developer may know exactly
- what you're doing with this cast (i.e., either you're not going to
- dereference the pointer, or you know yourself that the operand of the
- cast operation is suitably aligned), but the compiler is trying to help
- you with a potential problem.
-
- This may well not apply to your memory problems, but I hope this helps.
-
- Curt Wohlgemuth
- HP California Language Lab
-
- Official disclaimers apply to the above info, as usual...
-