Re: Weird string bug

From: Maarten Wiltink (maarten_at_kittensandcats.net)
Date: 10/22/04

  • Next message: Marco van de Voort: "Re: Question about Delphi versus other languages"
    Date: Fri, 22 Oct 2004 13:23:54 +0200
    
    

    "Francis Burton" <fburton@nyx.net> wrote in message
    news:737712375.90628@irys.nyx.net...
    [...]
    >> Nonetheless, AnsiStrings are not compatible with dynamic arrays of
    >> Char.

    > This seems to be the root of the problem. I guess I was seduced by
    > the statement in Borland's printed documentation to the effect that
    > conversions from "array of char" to string is handled automatically.

    The term "assignment compatible" occurs several times in the
    documentation. It means, more or less, that any conversions required
    are implicitly supplied by the compiler. It does not mean that the
    types can be treated as interchangeable. You have to allow the compiler
    to detect the need for the conversion.

    [...]
    > I wish the docs had been more explicit on this point!

    The documentation can never be exhaustive. Different people also want
    different things out of it. What may be obvious to an ex-C programmer
    may be hopelessly arcane to an ex-VB programmer, and the other way
    around. And that's without mentioning all the different Pascal
    programmers.

    > I am also a little puzzled why the compiler didn't flag this
    > conversion as dodgy. Was it because I explicitly used a String() cast?

    Quite possibly. Casting is a dangerous business; it tells the compiler
    to allow something it otherwise shouldn't. It always has the unspoken
    message that you know better than the compiler. If you (suspect that you)
    don't, skip the cast and pay careful attention to the error message you
    get. People don't do this nearly enough; we get several questions a
    month which have already been answered by the compiler error message.

    > Finally, I still can't get my head round the fact that the resulting
    > string appeared to be fine both in terms of content reported by the
    > debugger and in term of its length reported by Length - yet when I
    > assigned it to the Text property of the Edit control all hell broke
    > loose. Is this easily explainable?

    Perhaps it's something to do with reference counting. You did supply
    the terminating NUL which was my first guess.

    Groetjes,
    Maarten Wiltink


  • Next message: Marco van de Voort: "Re: Question about Delphi versus other languages"

    Relevant Pages

    • Re: OCaml: I am not impressed
      ... If you want, do the conversion here, but tell ... when there is in fact no reason to complain. ... you have to fight the compiler all the time. ... But it should be up to the programmer to decide what he wants. ...
      (comp.lang.lisp)
    • Re: [EGN] Hoisting Loop Invariants (Was: Re: [EGN] Numerical Accuracy)
      ... compiler out there somewhere that did as you claim. ... > the programmer has this knowledge, then the programmer should not use ... >> string in a loop, regardless of the blatant inefficiency of doing so. ...
      (comp.programming)
    • Re: The Philosophy of Programming?
      ... A compiler is free to ... >>is to allocate on entry to almost any block. ... > int foo{ ... But any programmer who wants to be more than a coder prefers, I think, ...
      (comp.programming)
    • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
      ... what experienced programmers do, ... the compiler doesn't have the free pass to /assume/ that the function ... Nobody has recommended doing all optimization by hand to my knowledge. ... Compiler behavior in optimization simply has no place in a language ...
      (comp.programming)
    • Re: Static/Strong/Implicit Typing
      ... and every programmer would instantly revere the static type analysis. ... will inform your compiler of your construction. ... the two varieties and consciously break the type disjointness. ... Common Lisp is not quite as abstract, ...
      (comp.lang.lisp)