Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
March 18, 2005 "Error: Error: conversion 8," | ||||
---|---|---|---|---|
| ||||
Has anyone seen this error before? I did a search on DigitalMars.com and didn't find anything with that error. It does not say a line or anything, but I think it has to do with this: char[] SomeFunction() { char[] str = "blah blah"; return str; } void main() { char[] ch = SomeFunction()[0..5]; } this code compiles and returns the right stuff. But it may be that the real program is too complicated and it's failing. Anyway, just thought I'd ask if someone has seen this before. thanks. jic |
March 18, 2005 Re: "Error: Error: conversion 8," | ||||
---|---|---|---|---|
| ||||
Posted in reply to jicman | jicman wrote: > Has anyone seen this error before? I did a search on DigitalMars.com and didn't > find anything with that error. It does not say a line or anything, but I think > it has to do with this: I'm not familiar with this error, but I've got some ideas. Here's what I did: I searched for "Error: conversion" in Phobos... which was found in ConvError (in dmd\src\phobos\stdconv\conv.d)... which was called by conv_error... which was called by toInt, toUint, toLong, toUlong. So it looks like the problem is in conv.d (std.conv). One of these function is being called incorrectly: toInt, toUint, toLong, toUlong Since I didn't see any of those functions in your sample, I guess the problem part is somewhere else. Hopefully, it'll be easier to find now. -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/ |
March 20, 2005 Re: "Error: Error: conversion 8," | ||||
---|---|---|---|---|
| ||||
Posted in reply to jicman | jicman says... I have not tested this, but several things seem quite fishy to me, and may have to do with you problem. >char[] SomeFunction() >{ >char[] str = "blah blah"; >return str; >} Returning str should not be possible, str is empty/undefinded. Since str is a local variable to SomeFunction(), as soon as you leave that function's scope str should not longer exist? >void main() >{ >char[] ch = SomeFunction()[0..5]; >} This means you are trying to slice a non-existing string. It also surprises me that you can use the slice "operator" on a function's return value. Just tested your code. As you say compiles with -w and runs as you expected. I am obviously not properly understanding something, about the local str var, or this is indeed illegal code, that just "happens" to work? How did you get that Error message though? AEon |
March 20, 2005 Re: "Error: Error: conversion 8," | ||||
---|---|---|---|---|
| ||||
Posted in reply to AEon | Since arrays are reference types, doesn't this mean that only the pointer/length pair of the array is local (on the stack) and the data it points to is on the heap/in the static data segment? The quick test program: #import std.stdio; #int main( char[][] args ) #{ # writefln( foo()[2..5] ); # return 0; #}# # #char[] foo() #{ # char[] str = "abfoocd"; # return str; #} prints "foo" as expected. Making str equal to "abfoocd".dup (meaning str points to a heap copy of the variable) also produces the expected output. On Sun, 20 Mar 2005 19:11:12 +0000 (UTC), AEon <AEon_member@pathlink.com> wrote: > jicman says... > > I have not tested this, but several things seem quite fishy to me, and may have > to do with you problem. > >> char[] SomeFunction() >> { >> char[] str = "blah blah"; >> return str; >> } > > Returning str should not be possible, str is empty/undefinded. Since str is a > local variable to SomeFunction(), as soon as you leave that function's scope str > should not longer exist? > >> void main() >> { >> char[] ch = SomeFunction()[0..5]; >> } > > This means you are trying to slice a non-existing string. It also surprises me > that you can use the slice "operator" on a function's return value. > > Just tested your code. As you say compiles with -w and runs as you expected. > > > I am obviously not properly understanding something, about the local str var, or > this is indeed illegal code, that just "happens" to work? > > How did you get that Error message though? > > AEon -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/ |
March 22, 2005 Re: "Error: Error: conversion 8," | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | J C Calvarese wrote: > jicman wrote: > >> Has anyone seen this error before? I did a search on DigitalMars.com and didn't >> find anything with that error. It does not say a line or anything, but I think >> it has to do with this: > > > I'm not familiar with this error, but I've got some ideas. > > Here's what I did: > > I searched for "Error: conversion" in Phobos... > which was found in ConvError (in dmd\src\phobos\stdconv\conv.d)... I think I meant "dmd\src\phobos\std\conv.d". (Oh, well, I'm guessing jicman figured out his problem regardless of my typographical error.) -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/ |
March 23, 2005 Re: | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | J C Calvarese says...
>
>J C Calvarese wrote:
>> jicman wrote:
>>
>>> Has anyone seen this error before? I did a search on DigitalMars.com
>>> and didn't
>>> find anything with that error. It does not say a line or anything,
>>> but I think
>>> it has to do with this:
>>
>>
>> I'm not familiar with this error, but I've got some ideas.
>>
>> Here's what I did:
>>
>> I searched for "Error: conversion" in Phobos...
>> which was found in ConvError (in dmd\src\phobos\stdconv\conv.d)...
>I think I meant "dmd\src\phobos\std\conv.d".
>
>(Oh, well, I'm guessing jicman figured out his problem regardless of my typographical error.)
yes. :-)
I am very forgiving. :-)
|
April 21, 2005 Re: "Error: Error: conversion 8," | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Stevenson | Alex Stevenson wrote: > > Since arrays are reference types, doesn't this mean that only the pointer/length pair of the array is local (on the stack) and the data it points to is on the heap/in the static data segment? > > The quick test program: > > #import std.stdio; > #int main( char[][] args ) > #{ > # writefln( foo()[2..5] ); > # return 0; > #}# > # > #char[] foo() > #{ > # char[] str = "abfoocd"; > # return str; > #} > > prints "foo" as expected. > > Making str equal to "abfoocd".dup (meaning str points to a heap copy of the variable) also produces the expected output. > > On Sun, 20 Mar 2005 19:11:12 +0000 (UTC), AEon <AEon_member@pathlink.com> wrote: > >> jicman says... >> >> I have not tested this, but several things seem quite fishy to me, and may have >> to do with you problem. >> >>> char[] SomeFunction() >>> { >>> char[] str = "blah blah"; >>> return str; >>> } >> >> >> Returning str should not be possible, str is empty/undefinded. Since str is a >> local variable to SomeFunction(), as soon as you leave that function's scope str >> should not longer exist? >> >>> void main() >>> { >>> char[] ch = SomeFunction()[0..5]; >>> } >> >> >> This means you are trying to slice a non-existing string. It also surprises me >> that you can use the slice "operator" on a function's return value. >> >> Just tested your code. As you say compiles with -w and runs as you expected. >> >> >> I am obviously not properly understanding something, about the local str var, or >> this is indeed illegal code, that just "happens" to work? >> >> How did you get that Error message though? >> >> AEon > > > > It's probably good to notice that while both of these work, you can't edit the first one (in linux, in windows, you can), only the .dup-ed one. -- -PIB -- "C++ also supports the notion of *friends*: cooperative classes that are permitted to see each other's private parts." - Grady Booch |
Copyright © 1999-2021 by the D Language Foundation