Joined: 06 Dec 2002 Posts: 117 Topics: 44 Location: Chennai,India
Posted: Wed Sep 21, 2005 9:15 am Post subject: PL/1 help
Hi Gurus,
Code:
PGM: PROC OPTIONS(MAIN);
DCL X FIXED BIN(2) BASED(P);
DCL Y FIXED BIN(7);
DCL Z PIC '999';
Y='1111111'B;
P=ADDR(Y);
Z=X;
PUT LIST('VALUE:',Z);
END PGM;
My assumption was Z value will be "3" (decimal equivalent is '11'B)
, but Z value was "127"(decimal equivalent is '1111111'B) displayed.
Why does PL/1 does not recognizes definition of X while assigning value of X to Z.
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
Posted: Wed Sep 21, 2005 10:18 am Post subject:
ravikumar_sri2001,
You have not defined P. It must be of the type POINTER; or, atleast FIX BIN(31). Since, you have not defined P, default datatype will be taken (FIX BIN(15) or FIX DEC(7,0); I forgot which one).
Perhaps, you should try again, with the correct datatypes.
Also, I do not quite understand, why are you expecting the answer to be 3? _________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes.
Joined: 06 Dec 2002 Posts: 117 Topics: 44 Location: Chennai,India
Posted: Thu Sep 22, 2005 8:30 am Post subject:
Hi Cogito,
"P" does not need declaration. PL/1 will define it implicitly as POINTER. Variables X and Y are occupying same storage. I have assigned '1111111'B to Y.
When i try assign value of "X" to Z, i thought that it will look definition of X and it will take 2 lowermost bits of X (sine it is defined as BIN(2)) and covert it into ZD and assign it to Z.
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
Posted: Thu Sep 22, 2005 9:00 am Post subject:
ravikumar_sri2001,
I do not have access to PL/I anymore; but, I am quite sure that implicit datatypes taken by variables can be FIXED BIN or FLOAT and not pointer.
Quote:
When i try assign value of "X" to Z, i thought that it will look definition of X and it will take 2 lowermost bits of X (sine it is defined as BIN(2)) and covert it into ZD and assign it to Z.
No. When you have a FIXED BIN variable as variable (p,q), then for, p<=15, it will stored in half-word binary i.e. 2 bytes.
[--Edited first line to have FLOAT and not FIXED DEC--] _________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum