There is a conversion function, which accepts "Width" up to which the returned value should be zero-extended as additional parameter. I was wondering, what would you expect from a library or unit function to do when this Width can't be satisfied withing given TString result value:
1. silently truncate
(simply return the converted number as TString of maximum possible length, for the truncated zeros do not make a change in numerical value assigned ot return string.)
2. return '' (empty string), which can be checked and detected by caller
3. truncate with some sort of warning, for suspiciously high Width silently truncated can hide a bug in program that will crash sometimes later something else less detectable
a) do it once per program run (i.e. like compiler that reports some conditions only once per function) b) report it with each call to function
in either case this warning might occur in test runs, indicating error or bug in calling program
4. raise RuntimeWarning() { deprecated by Frank }
5. raise RuntimeError() to abort the program
What is the behavior you'd prefer for such a library function? Example of the function might be:
Integer2StringWidth (i: Integer; Width: Integer): TString;
So, for example, if High(TString) = 2048, and the code is:
WriteLn (Integer2StringWidth (i, 2200));
what should be done?
(NOTE: this is not the actual function, but a meaningless, but simpler example.)
Thank you, Mirsad
Mirsad Todorovac wrote:
... snip ...
So, for example, if High(TString) = 2048, and the code is:
WriteLn (Integer2StringWidth (i, 2200));
what should be done?
(NOTE: this is not the actual function, but a meaningless, but simpler example.)
As long as any valid call cannot return the empty string, I consider using that as an error signal the best method. That passes the decision up to a higher level, which may know what to do. Then the user code should be:
s := Integer2StringWidth(i, 2200); IF strlen(s) > 0 THEN writeln(s) ELSE BEGIN (* take steps *) END;
Hi Mirsad!
On Wed, Jun 11, 2003 at 08:41:03PM +0200, Mirsad Todorovac wrote:
Integer2StringWidth (i: Integer; Width: Integer): TString;
What about type TWidth = 0 .. 2048;
Integer2StringWidth (i: Integer; Width: TWidth): TString;
or Integer2StringWidth (i: Integer; Width: Integer; var ErrorCode: Integer): TString;
Eike