flat assembler
Message board for the users of flat assembler.

Index > Heap > Philosophical Question (zero length and empty strings)

Author
Thread Post new topic Reply to topic
Sasha



Joined: 17 Nov 2011
Posts: 93
Sasha
I think this question is not directly related to any topic, so I'm posting it here.
Are two strings with the zero length equal to one another or not?
Post 25 Jun 2014, 22:56
View user's profile Send private message Reply with quote
Frank



Joined: 17 Jun 2003
Posts: 100
Frank
Yes.
Post 25 Jun 2014, 23:05
View user's profile Send private message Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
This is a great question!

It may depend on your definition of "string". If you consider a string to be an object then an empty string's value is equal to another empty string's value. However, if you consider a string to be an array of characters than there is no way to compare elements that don't exist so undefined perhaps, but for programmer sanity we just consider than equal.

What might be more interesting is if a NULL string is equal to an EMPTY string, since both are essentially zero length and contain no elements. But then you have to ponder the meaning of "equal", is it a reference, is it a value etc.

In SQL NULL is not equal to NULL. I recall this biting me badly when I was using a NOT IN statement.
Post 26 Jun 2014, 00:08
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Sasha



Joined: 17 Nov 2011
Posts: 93
Sasha
For example, two zeroterminated strings, having only zero bytes can be considered equal, because 0=0. But when you want to compare two memory locations and give the length argument=0, then what to return? FreshLib, as I can see, treats such strings as not equal. I haven't yet seen how the wide used standards treats such cases.
Post 26 Jun 2014, 00:55
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 18:08; edited 1 time in total
Post 26 Jun 2014, 03:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
HaHaAnonymous wrote:
I wouldn't even bother to compare two empty strings as I have nothing to compare.
An empty string is still a valid string. So you still have a string to compare with another string.

Q: Are those two boxes over there both empty?
HHAs answer: No. One of them is empty so they can't both be empty.
Post 26 Jun 2014, 03:12
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Sasha wrote:
FreshLib, as I can see, treats such strings as not equal.


FreshLib treats two empty strings as equal, but NULL pointer is not equal to an empty string. Also, two NULL pointers are equal.

Code:
empty1 dd 0
empty2 dd 0

stdcall  StrCompCase, 0, 0   ; returns EQ
stdcall  StrCompCase, 0, empty1 ; return NEQ
stdcall  StrCompCase, empty1, empty2 ; returns EQ
stdcall  StrCompCase, empty1, empty1 ; returns EQ    

_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9
Post 26 Jun 2014, 04:53
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Sasha wrote:
Are two strings with the zero length equal to one another or not?


YES, definitely. You invented ^^^ a pseudo-problem. But here a real problem 4u:

Are the 2 Unicode strings "caño'n" and "can~ón" (the apo and wave do represent 2 strange things called "combining accent" and are supposed to land above of the "o" and "n") EQUAL or not ?
Post 26 Jun 2014, 06:24
View user's profile Send private message Reply with quote
Sasha



Joined: 17 Nov 2011
Posts: 93
Sasha
Post 26 Jun 2014, 08:37
View user's profile Send private message Reply with quote
Sasha



Joined: 17 Nov 2011
Posts: 93
Sasha
JohnFound, can you then distinguish between two variants? I don't know if you need to do it in a real application. But if you do, then you need to check it separately. I found this http://stackoverflow.com/questions/19034858/return-value-of-memcmpptr1-ptr2-0 . It seems, that people intuitively think it must return zero or equal, so best the best way is to do it..
Post 26 Jun 2014, 08:59
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Sasha wrote:
is this the same problem discussed here


More likely here: http://www.unicode.org/reports/tr36/#international_domain_names

Quote:
There is a natural desire for people to see domain names in their own languages and writing systems


YES, it's my natural desire to stay with 26 simple letters "A" to "Z" and deprecate both decorated letters (like French, Hungarian, ...) and open-end alphabets (CJK & Co).
Post 26 Jun 2014, 08:59
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Sasha wrote:
JohnFound, can you then distinguish between two variants?

Which two variants? I gave four in my post.

_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9
Post 26 Jun 2014, 09:59
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Sasha



Joined: 17 Nov 2011
Posts: 93
Sasha
JohnFound, I ment you don't know if it was zero length string. I am making a such function, that returns a number of equal bytes in eax and a flag that tells about equality, so if eax=0 and it is equal, means that the length was zero. I still do not know if it will be useful.

DOS386, it seems like pattern recognition problem?
Post 26 Jun 2014, 12:06
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.