News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Two HiSoft Pascal' syntax questions

Started by the graveborn, 13:45, 27 August 21

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

the graveborn

Hey there, everybody; a long time has passed since I last asked a programming-related question, on this forum or anywhere else, but I've encountered two obstacles whilst trying to develop my latest program on and for the Amstrad CPC, and I'm uncertain if the obstacles are caused by me being ignorant or by the tools I'm using not being able to do what I'm asking of them, those tools being HiSoft Pascal for CP/M-80 and HiSoft Pascal Amstrad CPC464.

The first obstacle is that I've been unable to figure out the syntax for pointing a pointer-variable to a non-pointer-variable; in Pascal in Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition) the syntax would be...

program PointingTest( output );
var
  i : integer;
  pointer : ^integer;
begin
  i := 0;
  pointer := @i;
  writeln( 'Before: ', i:0, '.' );
  pointer^ := 1;
  writeln( 'After:  ', i:0, '.' )
end.


Example output:

Before: 0.
After:  1.


...but my every attempt to figure out the syntax in HiSoft Pascal' has been a failure; eg., using the above syntax, pointer := @i;, results in the error "12. Factor expected." when trying to compile it using HiSoft Pascal for CP/M-80.

The second obstacle is that I've no idea about the syntax for getting the address pointed to by a pointer-variable and assigning it to be the value of an INTEGER-variable, or the reverse, assigning the value of an INTEGER-variable to be the address pointed to by a pointer-variable; in C in Leonardo IDE 3.4.1 the syntax would be...

#include <stdio.h>

#define k_Limit 3

void main( void )
{
  int i = 0, array[ k_Limit ], *pointer;

  for( ; i < k_Limit; i ++ )
  {
    array[ i ] = i;
    pointer = array + i; /* Simple pointer arithmetic to calculate the address of the `i`th cell of the array `array`. */
    printf( "Address: %p.\n", pointer );
    printf( "Value:   %i.\n", *pointer );
    printf( "Value is correct: %s.\n", ( *pointer == i )?"yes":"no" );
    if( i + 1 < k_Limit )
      printf( "\n" );
  }
}


Example output:

Address: 0x00000676.
Value:   0.
Value is correct: yes.

Address: 0x00000678.
Value:   1.
Value is correct: yes.

Address: 0x0000067a.
Value:   2.
Value is correct: yes.
Current project: SDL2 joystick interrogator

Bread80

I just had a scroll through the manual at http://www.primrosebank.net/computers/mtx/documents/HiSoftPascalManual.pdf and it looks like the @ operator isn't supported but there's an addr() function which does the same thing. Beyond that it might be down to peek() and poke() functions. Their examples for peek certainly make it look that way!

the graveborn

@Bread80 Thank you for your response..! I'd already read the manual, and so I already knew about the ADDR() function, and that function isn't useful in this situation as it has the "signature" ADDR( generic ) : INTEGER; and so attempting to use that function to point a pointer-variable to a non-pointer-variable – eg., pointer := ADDR( i ); – results in the error "10. Wrong type." (to be useful in this situation, that function would need to have the "signature" ADDR( generic ) : ^generic;). I don't know if it's what you meant when you suggested using the POKE() procedure and the PEEK() function, but I did figure out a workaround using ADDR() and POKE() – it is (I think) unnecessarily long, but it (seems to) work...

PROGRAM PointingTest;
VAR
i, a1, a2 : INTEGER;
pointer : ^INTEGER;
BEGIN
i := 0;
WRITELN( 'Before: ', i:0, '.' );
a1 := ADDR( i );
a2 := ADDR( pointer );
POKE( a2, a1 );
pointer^ := 1;
WRITELN( 'After:  ', i:0, '.' )
END.


Example output:

Before: 0.
After:  1.
Current project: SDL2 joystick interrogator

Singaja

#3
My Pascal is a little rusty and I don't know what HiSoft syntax allows, but I got this in some online compiler:


program PointingTest( output );
type Rec = record
  case integer of
    0: (
        value: integer;
      );
    1: ( pointer: ^integer;
    )
end;
var
  i,y : Rec;
begin
  i.value := 0;
  writeln( 'Before: ', i.value:0, '.' );
  y.value := 1;
  i.pointer := y.pointer;
  writeln( 'After: ', i.value:0, '.' )
end.

outputs


Before: 0.
After: 1.

Not sure if that's of any use.

Powered by SMFPacks Menu Editor Mod