D - char literal cast to char and char[]
- Matthew Wilson (7/9) Mar 21 2003 literal.
- Walter (5/14) Mar 22 2003 the
- Matthew Wilson (20/36) Mar 22 2003 What are the arguments in favour?
- Walter (8/23) Mar 22 2003 Simplicity.
- Matthew Wilson (4/33) Mar 22 2003 Come on, old bean! I need more than that.
- Vathix (4/4) Mar 31 2003 I think, in that case, it should call the function that takes a char if
obvious. It seemed as though a char literal could be passed resolved into both a char and a char[] parameter.Matthew: I'll pursue this myself, but you may recognise somethingWalter: Yes, that is correct. You can force the issue using a cast on theliteral. Is this something that's been deliberate, and subject to debate/experimentation? It seems like a bad idea to me, since a instance of a type is very different from an array of instances of the same (or any other) type
Mar 21 2003
"Matthew Wilson" <dmd synesis.com.au> wrote in message news:b5gt7a$1pf1$1 digitaldaemon.com...theobvious. It seemed as though a char literal could be passed resolved into both a char and a char[] parameter.Matthew: I'll pursue this myself, but you may recognise somethingWalter: Yes, that is correct. You can force the issue using a cast onliteral. Is this something that's been deliberate, and subject to debate/experimentation? It seems like a bad idea to me, since a instanceofa type is very different from an array of instances of the same (or any other) typeI have some misgivings about it, but I think it needs a chance.
Mar 22 2003
What are the arguments in favour? Against are the obvious confusing one I've said, and the practical one I was discussing with you in the emails, namely that overloading char[][] tokenise(char[] string, char[] delimiter, bit bElideBlanks, bit bNullTerminateSlices); with char[][] tokenise(char[] string, char delimiter, bit bElideBlanks, bit bNullTerminateSlices); means that in client code I cannot type char[][] tokens = tokenise(source, ';', true, false); without getting a compilation error, which seems preposterous. The overloads are deliberate because - as you are aware from the offline discussion - I am aiming for maximal performance, so do not wish to treat a single char as an array of one element. (And why should I? Isn't D supposed to simplify programming whilst not reducing programmer's ability for efficiency?) Please explain. Matthew "Walter" <walter digitalmars.com> wrote in message news:b5i50d$2o49$1 digitaldaemon.com..."Matthew Wilson" <dmd synesis.com.au> wrote in message news:b5gt7a$1pf1$1 digitaldaemon.com...intoobvious. It seemed as though a char literal could be passed resolvedMatthew: I'll pursue this myself, but you may recognise somethingboth a char and a char[] parameter.theWalter: Yes, that is correct. You can force the issue using a cast onliteral. Is this something that's been deliberate, and subject to debate/experimentation? It seems like a bad idea to me, since a instanceofa type is very different from an array of instances of the same (or any other) typeI have some misgivings about it, but I think it needs a chance.
Mar 22 2003
"Matthew Wilson" <dmd synesis.com.au> wrote in message news:b5ieup$2uqp$1 digitaldaemon.com...What are the arguments in favour?Simplicity.Against are the obvious confusing one I've said, and the practical one Iwasdiscussing with you in the emails, namely that overloading char[][] tokenise(char[] string, char[] delimiter, bit bElideBlanks, bit bNullTerminateSlices); with char[][] tokenise(char[] string, char delimiter, bit bElideBlanks, bit bNullTerminateSlices); means that in client code I cannot type char[][] tokens = tokenise(source, ';', true, false); without getting a compilation error, which seems preposterous. Theoverloadsare deliberate because - as you are aware from the offline discussion - Iamaiming for maximal performance, so do not wish to treat a single char asanarray of one element. (And why should I? Isn't D supposed to simplify programming whilst not reducing programmer's ability for efficiency?)The ambiguity for overloads is a problem. I'll think about it some more.
Mar 22 2003
"Walter" <walter digitalmars.com> wrote in message news:b5ih1d$30ej$1 digitaldaemon.com..."Matthew Wilson" <dmd synesis.com.au> wrote in message news:b5ieup$2uqp$1 digitaldaemon.com...Come on, old bean! I need more than that.What are the arguments in favour?Simplicity.IAgainst are the obvious confusing one I've said, and the practical one Iwasdiscussing with you in the emails, namely that overloading char[][] tokenise(char[] string, char[] delimiter, bit bElideBlanks, bit bNullTerminateSlices); with char[][] tokenise(char[] string, char delimiter, bit bElideBlanks, bit bNullTerminateSlices); means that in client code I cannot type char[][] tokens = tokenise(source, ';', true, false); without getting a compilation error, which seems preposterous. Theoverloadsare deliberate because - as you are aware from the offline discussion -amaiming for maximal performance, so do not wish to treat a single char asanarray of one element. (And why should I? Isn't D supposed to simplify programming whilst not reducing programmer's ability for efficiency?)The ambiguity for overloads is a problem. I'll think about it some more.
Mar 22 2003
I think, in that case, it should call the function that takes a char if there's one character in the quotes. Even if it doesn't seem to follow a pattern, both functions should do the same thing, and char is accessed faster :)
Mar 31 2003