HP3000-L Archives

October 1997, Week 5

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Reply To:
Date:
Thu, 30 Oct 1997 12:24:15 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (142 lines)
Steve Dirickson writes:

><<I also understand that the item's addresses must be byte addresses.>>
>
>
>Definitely not. The distinction between 'byte address' and 'word address'
>matters in Transact, but not C.

It does matter in C, though specifically not for FFILEINFO. Word and
halfword addresses must generally be aligned on word and halfword
boundaries or a trap will result.

>     mpe_ffileinfo ( msg, 1, cbuf, 2, (char*)&fop, 4, (char*)&recs, 10,
>(char*)&eof );
>     if ( ccode () != CCE ) doferr ( msg, "FG:recsize" );>>
>
>
>Constructs like this will generally work (since the casts don't make any
>difference in the generated code), but they will also typically generate
>the diagnostic about "parameter nn points to a less strictly aligned
>type".

FFILEINFO takes ANYPTRS (void *'s) as addresses to which it returns data,
which means that it has no alignment requirements. Routines which
specifically expect word or halfword reference parameters may abort when
passed addresses with incorrect alignment. In these cases, though, the
compiler will generate appropriate compile errors:

>/l all
>    1     #pragma intrinsic PAUSE
>    2     #include <stdio.h>
>    3     main()
>    4     {
>    5         char   pauseStuff[8];
>    6         float  pauseTime = 5.0;
>    7
>    8         memcpy(pauseStuff + 1, &pauseTime, sizeof(pauseTime));
>    9         printf("Calling PAUSE.\n");
>   10         PAUSE(pauseStuff + 1);
>   11     }
>/ccxl *,,$null
>
>cc: "QEDITSCR.PUB.CASEDEV", line 10: error 1632: Argument 1 points to
>incorrect
>type.
>RUN
>ccomxl.pub.sys;INFO='';PARM=3;xl="qcompxl.pubnew.robelle,qcompxl.pub.robelle
>"
>Program terminated in an error state. (CIERR 976)
>End Run

That said, however, for intrinsics it usually doesn't matter:

>/d1
>    1    _#pragma intrinsic PAUSE
>1 line Deleted!
>/ccxlgo *,$null
>
>End Run
>
>END OF COMPILE
>
>HP Link Editor/iX (HP30315A.04.27) Copyright Hewlett-Packard Co 1986
>
>LinkEd> LINK FROM=$OLDPASS;
>RL=LIBCINIT.LIB.SYS,LIBCANSI.LIB.SYS,LIBMANSI.LIB.S
>YS, LIBCRAND.LIB.SYS
>
>END OF LINK
>
>Calling PAUSE.
>End Run

Without the INTRINSIC declaration, the compiler can't check the arguments
and the compile completes without error. However, the program runs
anyway. Since system intrinsics must take reference parameters from
languages with the ability to store data on other than natural boundaries
(e.g., COBOL and PASCAL), they don't complain when passed misaligned
addresses.

On the other hand, user-written C or Pascal library procedures *will*
abort unless they, too, have special code to align misaligned data.
(Generally, this means that data is copied to and from reference
parameters via byte moves.) For example:

>/l all
>    1     #pragma intrinsic PAUSE
>    2     #include <stdio.h>
>    3     main()
>    4     {
>    5         char   pauseStuff[8];
>    6         float  pauseTime = 5.0;
>    7
>    8         memcpy(pauseStuff + 1, &pauseTime, sizeof(pauseTime));
>    9         printf("Calling pausePlusTwo.\n");
>   10         pausePlusTwo(pauseStuff + 1);
>   11     }
>   12     int pausePlusTwo(basePause)
>   13     float *basePause;
>   14     {
>   15         float realPause = *basePause + 2;
>   16         printf("Calling PAUSE.\n");
>   17         PAUSE(&realPause);
>   18     }
>/ccxlgo *,$null
>
>End Run
>
>END OF COMPILE
>
>HP Link Editor/iX (HP30315A.04.27) Copyright Hewlett-Packard Co 1986
>
>LinkEd> LINK FROM=$OLDPASS;
>RL=LIBCINIT.LIB.SYS,LIBCANSI.LIB.SYS,LIBMANSI.LIB.S
>YS, LIBCRAND.LIB.SYS
>
>END OF LINK
>
>Calling pausePlusTwo.
>**** Data memory protection trap (TRAPS 68).
>
>ABORT: $OLDPASS.PUB.CASEDEV
>NM PROG  5ed.0000713c pausePlusTwo+$10
>RUN $OLDPASS
>Program terminated in an error state. (CIERR 976)
>End Run



-- Bruce


--------------------------------------------------------------------------
Bruce Toback    Tel: (602) 996-8601| My candle burns at both ends;
OPT, Inc.            (800) 858-4507| It will not last the night;
11801 N. Tatum Blvd. Ste. 142      | But ah, my foes, and oh, my friends -
Phoenix AZ 85028                   | It gives a lovely light.
btoback AT optc.com                |     -- Edna St. Vincent Millay
Unsolicited mail to [log in to unmask] will be inspected for a
fee of US$250. Mailing to said address constitutes agreement to
pay, including collection costs.

ATOM RSS1 RSS2