duvalj@prism.cs.orst.edu (Joseph Edward Duval) (07/27/89)
I am trying to declare a constant in my UNIX (HP) pascal program that is is of TYPE record. In the manual it says it can be done but says nothing about how. Does anyone out there know how to do this? What I have now is: type sequence = record first : byte; next : byte; pcount : byte; param : packed array [1..8] of byte; private : byte; inter : byte; nxtlast : byte; last : byte; end; . . . const NUL = 0; NULSEQ = sequence (NUL, NUL, NUL, (NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL), (NUL, NUL, NUL, NUL); This doesn't work. Thanks for the help! - Joe Duval {duvalj@prism.CS.ORST.EDU}
louxj@jacobs.CS.ORST.EDU (John W. Loux) (07/27/89)
In article <11843@orstcs.CS.ORST.EDU> duvalj@prism.CS.ORST.EDU (Joseph Edward Duval) writes: > >I am trying to declare a constant in my UNIX (HP) pascal program that is >is of TYPE record. In the manual it says it can be done but says nothing >about how. Does anyone out there know how to do this? > >What I have now is: > > type > sequence = record > first : byte; > next : byte; > pcount : byte; > param : packed array [1..8] of byte; > private : byte; > inter : byte; > nxtlast : byte; > last : byte; > end; > > . > . > . > const > NUL = 0; > NULSEQ = sequence (NUL, NUL, NUL, > (NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL), > (NUL, NUL, NUL, NUL); > >This doesn't work. > >Thanks for the help! > - Joe Duval {duvalj@prism.CS.ORST.EDU} The following compiles (and is fairly well documented in the HP-UX 6.5 Pascal Language Reference under records and arrays): program poop (input, output); type byte = 0..255; paramtype = packed array[1..8] of byte; sequence = record first : byte; next : byte; pcount : byte; param : paramtype; private : byte; inter : byte; nxtlast : byte; last : byte; end; const nul = 0; nulseq = sequence[ first : nul, next : nul, pcount : nul, param : paramtype[nul, nul, nul, nul, nul, nul, nul, nul], private : nul, inter : nul, nxtlast : nul, last : nul]; begin end. Note that you must declare the record fields, and that to initialize the param array, you must have a paramtype to build the constructor. John W. Loux louxj@jacobs.cs.orst.edu
conway@hpdtl.HP.COM (Daniel F. Conway) (07/28/89)
duvalj@prism.cs.orst.edu (Joseph Edward Duval) writes: | | I am trying to declare a constant in my UNIX (HP) pascal program that is | is of TYPE record. In the manual it says it can be done but says nothing | about how. Does anyone out there know how to do this? | | What I have now is: [example deleted] | This doesn't work. Yes, the manual has no examples. An earlier manual has a partial example that would get you all the way there if you experimented a bit, but the example was unfortunately deleted in the current documentation. Try doing it this way: program goodstr; type byte = 0 .. 255; pab8 = packed array [1..8] of byte; sequence = record first : byte; next : byte; pcount : byte; param : pab8; private : byte; inter : byte; nxtlast : byte; last : byte; end; const NUL = 0; NULSEQ = sequence [first: NUL, next: NUL, pcount: NUL, param: pab8 [NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL], private: NUL, inter: NUL, nxtlast: NUL, last: NUL]; begin end. This really does work; I compiled it on a 9000/350 just to make sure (you didn't say what type of machine you are using; I didn't try it on an 800 or a 3000). What I did was change the parens (Turbo Pascal convention) to square brackets (HP convention); added field names to each value being set in the constant declaration (the HP compiler wisely refuses to depend on declaration order of the fields to figure out which ones to assign each value; I think that Turbo Pascal also requires this); made the declaration of the packed array an explicitly named type, and added it to the constant initializer following its field name; explicitly declared the type 'byte' which is not built-in to HP Pascal; and deleted one excess left paren. Dan Conway dan_conway@hplabs.hp.com