- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- Pascal empty string comparison
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2010 03:30 PM
тАО02-24-2010 03:30 PM
Yesterday, I found I was most mistaken...here is a simple test program...
$ type TEST_EMPTY_STRING.PAS
program test_empty_string (output);
VAR
stringy_bark : varying[200] of char;
begin
stringy_bark := ' ';
if stringy_bark = ''
then writeln ('Space equates to empty')
else writeln ('Space does not equate to empty');
end.
and the output...
$ pas TEST_EMPTY_STRING.PAS
$ link TEST_EMPTY_STRING
$ run TEST_EMPTY_STRING
Space equates to empty
$ pascal/vers
HP Pascal I64 V6.1-120 on OpenVMS I64 V8.3
Am I going loopy, or is there something I have misunderstood....
(For my real code, I just replaced the test against an empty string with a test of length(string) = 0).
Solved! Go to Solution.
- Tags:
- Pascal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2010 03:45 PM
тАО02-24-2010 03:45 PM
SolutionNo, you're not going loopy - but the code is behaving as it should (although not as you would like).
The Pascal Language Reference Manual says,
"The relational operators are legal for testing strings of different lengths. ... The shorter of the two strings is padded with blanks for the comparison."
So the result you got is the correct behaviour.
If you want to *not* pad with blanks, use the EQ or NE functions. Doing so can potentially save processing cycles too, because Pascal will first compare the string lengths before testing each character.
Regards,
Jeremy Begg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2010 03:52 PM
тАО02-24-2010 03:52 PM
Re: Pascal empty string comparison
Someone just said to me that I should RTFM before putting this question up....and they were right...
I think that does mean I am going loopy...or just losing a few brain cells.
Thanks,
chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2010 03:53 PM
тАО02-24-2010 03:53 PM
Re: Pascal empty string comparison
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2010 07:44 PM
тАО02-27-2010 07:44 PM
Re: Pascal empty string comparison
Yes, that's the case for C and C++. And Pascal on HP-UX and MPE/iX. Only COBOL pads with spaces.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2010 09:08 PM
тАО03-11-2010 09:08 PM
Re: Pascal empty string comparison
The Extended Pascal standard says to pad with spaces. The EP standard also defines the NE, EQ, LT, etc. string functions mentioned by Jeremy.
From the Extended Pascal standard (the standard with variable length strings):
6.8.3.5 Relational operators
When the relational-operators =, <>, <, >, <=, and >= are used to compare operands of
compatible string-types (see 6.4.5), they shall denote the lexicographic relations defined below.
This lexicographic ordering shall impose a total ordering on values of a string-type.
Let s1 and s2 be two values of compatible string-types where the length of s1 is less than or equal to the length of s2, let n1 be the length of s1, and let n2 be the length of s2; then
s1 = s2 iff (for all i in [1..n1]: s1[i] = s2[i])
and (for all i in [n1+1..n2]: ' ' = s2[i])
s1 < s2 iff ( there exists p in [1..n1]:
(for all i in [1..p-1]: s1[i] = s2[i])
and s1[p] < s2[p] )
or
( (for all i in [1..n1]: s1[i] = s2[i] )
and ( there exists p in [n1+1..n2]:
(for all i in [n1+1..p-1]: ' ' = s2[i])
and ' ' < s2[p]) )
The definitions of operations >, <>, <=, and >= are derived from the definitions of = and <.
The definitions of the relational operators for the length of s1 greater than the length of s2 are derived from the definitions of the operators for the length of s1 less than or equal to the length of
s2.
When comparing a char-type value with a string-type value, the char-type value shall be treated as a value of the canonical-string-type with length 1 and with the component-value equal to the
char-type value.
NOTES
2 For comparison of values of compatible char-types or string-types, the relational-operators effectively extend the shorter value with trailing spaces to the length of the longer value.
3 String-type ordering is defined in terms of the char-type ordering, in turn defined in table 6.