flat assembler
Message board for the users of flat assembler.
Index
> Main > design of substring routine [FASMLIB] |
Return what? | ||||||||||||||
|
||||||||||||||
Total Votes : 11 |
Author |
|
UCM 14 Aug 2006, 17:07
I think that ZF should be set and an empty string should be returned, since it is not hard to do a second 'jz error' in case the application wants to consider it an error. Also you could set a compile-time flag to switch between behaviours.
|
|||
14 Aug 2006, 17:07 |
|
vid 14 Aug 2006, 17:14
surely no compile-time flag
too much generality causes confusion. thanks for opinion |
|||
14 Aug 2006, 17:14 |
|
MazeGen 14 Aug 2006, 17:25
It should return an error because:
UCM, you forgot to vote. |
|||
14 Aug 2006, 17:25 |
|
r22 14 Aug 2006, 21:56
I think you should consider returning an empty string as well as set the zf, so that your libraries functions work fluently with eachother.
While error checking is important and part of good coding practice it should not be mandatory. For example, what if someone wishes to append the returned string from your substring function to a pre existing string and the person doesn't mind of the returned substring has no characters in it? You are forcing them to use unneeded error checking logic. This error checking logic becomes even more exagerated if the returned strings of multiple calls to sub are appended together into one string. If the purpose of this lib is to emulate high level string functionality using assembly then you should allow such high level approaches as IE strNew = strT1.substr(4, 3) + strT2.substr(3, 1) + strT3.substr(7, 10); If strT2's sub string is a null the appending still works because a null string is appended to strNew. |
|||
14 Aug 2006, 21:56 |
|
ChrisLeslie 18 Aug 2006, 01:33
vid
My preference would be to make you routine as robust as possible by detecting any breach of the string's bounds at the start of the routine. Therefore, at least, if both index OR index+len are either before OR after the string's bounds then return a null string and particular flags set. I don't like the idea of returning an incomplete (less than len) string. I would then leave it up to the main application to optionaly examine the flags and act as appropriate to the circumstances. BTW, will you call the first position in the string as index=0, or index=1? Just curious. Chris |
|||
18 Aug 2006, 01:33 |
|
vid 18 Aug 2006, 08:04
Quote: BTW, will you call the first position in the string as index=0, or index=1? of course index 0 - it's "behind 0th char", like 1 is "behind 1st char" etc. making it otherwise will surely result in some incrementing and decrementing. btw, this number is same as index into array, when accessing memory. But thanks for question, i have to add this to docs, i thought it is obvious enough. about the non-flags - maybe i could design another routine that will surely return entire substring, and another that will return partial/empty string also. but i don't have any idea abou how to name them. also, checking one flag per call isn't that much, but you are right most of time it's annoying. |
|||
18 Aug 2006, 08:04 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.