Discussion:
GNU Pascal syntax?
(too old to reply)
Haastrup
2004-12-14 18:26:48 UTC
Permalink
Hello.

Why does a construction like the following fail compilation in GNU
Pascal. How am i supposed to write it?

program test;

type
AVEC=record
x,y:double;
end;

function test(u:AVEC):AVEC;
begin
test.x:=u.x;
test.y:=u.y;
end;

begin
end.

Output from compiler:
in function `Test':
request for field `X' in something not a record, schema or object
request for field `Y' in something not a record, schema or object
warning: return value of function not assigned


regards Søren.

Regards S. Haastrup.
(***@nameplanet.com)
(a semi no spam address)
Norm Mann
2004-12-15 02:23:11 UTC
Permalink
Post by Haastrup
Why does a construction like the following fail compilation in GNU
Pascal. How am i supposed to write it?
program test;
type
AVEC=record
x,y:double;
end;
Even though you've specified what an avec record should contain, you
haven't declared any avec variables.
Post by Haastrup
function test(u:AVEC):AVEC;
begin
test.x:=u.x;
test.y:=u.y;
end;
begin
Here you should be initializing a record and setting up a call to the test
function.
(not to mention providing a way to see if it worked correctly.)
Post by Haastrup
end.
request for field `X' in something not a record, schema or object
request for field `Y' in something not a record, schema or object
warning: return value of function not assigned
hope this helps.
Haastrup
2004-12-15 08:51:47 UTC
Permalink
On Wed, 15 Dec 2004 02:23:11 GMT, "Norm Mann" <***@hotmail.com>
wrote:

Thanks, but it still fails with the same errors if i do what you
suggested. I am just clueless, since the constructions works
in FPC and delphi.
Post by Norm Mann
Even though you've specified what an avec record should contain, you
haven't declared any avec variables.
I dont think that is reqired. A type can be defined without
having to declare an instance of it.
Post by Norm Mann
Here you should be initializing a record and setting up a call to the test
function.
(not to mention providing a way to see if it worked correctly.)
If i do that it still fails.

program test;

type
AVEC=record
x,y:double;
end;

function test (u:AVEC):AVEC;
begin
test.x:=u.x;
test.y:=u.y;
end;

var a,b:AVec;
begin
a.x:=1;
a.y:=-1;

b:=test(a);

end.

Output from compiler

In function `Test':
request for field `X' in something not a record, schema or object
request for field `Y' in something not a record, schema or object
warning: return value of function not assigned

Regards S. Haastrup.
(***@nameplanet.com)
(a semi no spam address)
Norm Mann
2004-12-16 03:29:30 UTC
Permalink
"> Thanks, but it still fails with the same errors if i do what you
Post by Haastrup
suggested. I am just clueless, since the constructions works
in FPC and delphi.
Post by Norm Mann
Even though you've specified what an avec record should contain, you
haven't declared any avec variables.
I dont think that is reqired. A type can be defined without
having to declare an instance of it.
In essence, I agree, but you aren't using FPC nor Delphi and some
differences are bound to show up. Even though I have seen programs that
declare the variables just above the main procedure, I was thinking to
declare them before the test function, just after the type statement.
Unfortunately, the computer that has my Pascal compiler has crashed so I
can't see if your code will run on mine. I did have a couple other ideas,
but I think they would result in a few more error messages than you got.

Later-
Niclas Pettersson
2005-01-05 15:23:55 UTC
Permalink
Post by Haastrup
Thanks, but it still fails with the same errors if i do what you
suggested. I am just clueless, since the constructions works
in FPC and delphi.
Post by Norm Mann
Even though you've specified what an avec record should contain, you
haven't declared any avec variables.
I dont think that is reqired. A type can be defined without
having to declare an instance of it.
Post by Norm Mann
Here you should be initializing a record and setting up a call to the test
function.
(not to mention providing a way to see if it worked correctly.)
If i do that it still fails.
program test;
type
AVEC=record
x,y:double;
end;
function test (u:AVEC):AVEC;
begin
test.x:=u.x;
test.y:=u.y;
end;
var a,b:AVec;
begin
a.x:=1;
a.y:=-1;
b:=test(a);
end.
Output from compiler
request for field `X' in something not a record, schema or object
request for field `Y' in something not a record, schema or object
warning: return value of function not assigned
Regards S. Haastrup.
(a semi no spam address)
Hi. There is no test.x or test.y in the program
Declare them with:

VAR x : double;
y : double;

"function test (u:AVEC):AVEC;" does not return anyting.
If you want it to do so you may write like this:

function testf (u:AVEC):AVEC;
VAR result : AVEC;
begin
test.x:=u.x;
test.y:=u.y;

result.x := test.x +1;
result.y := test.y -1;

testf := result;

end;

And finaly the name of the program and than name of the funcion are
same. Rename the program or the function.

/Nicks

Loading...