www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Compile time string manipulation caveats

reply Hasan Aljudy <hasan.aljudy gmail.com> writes:
I discovered that compile-time functions can't use non-static arrays .. 
implying that we can't use char[] which is a dynamic array.
However, this is essential for any non-trivial string parsing (even for 
trivial ones, in fact), so how do we overcome this problem?
Feb 24 2007
parent reply Gregor Richards <Richards codu.org> writes:
Hasan Aljudy wrote:
 I discovered that compile-time functions can't use non-static arrays .. 
 implying that we can't use char[] which is a dynamic array.
 However, this is essential for any non-trivial string parsing (even for 
 trivial ones, in fact), so how do we overcome this problem?
 
Uh, compile-time functions /can/ use dynamic arrays. - Gregor Richards
Feb 24 2007
parent reply Hasan Aljudy <hasan.aljudy gmail.com> writes:
Gregor Richards wrote:
 Hasan Aljudy wrote:
 I discovered that compile-time functions can't use non-static arrays 
 .. implying that we can't use char[] which is a dynamic array.
 However, this is essential for any non-trivial string parsing (even 
 for trivial ones, in fact), so how do we overcome this problem?
Uh, compile-time functions /can/ use dynamic arrays. - Gregor Richards
oh, sorry my mistake, I had a piece of code which was refusing to be compile-time executed, I didn't see anything wrong with it, but then I saw this: ------------ expressions in the function may not: * use pointers, delegates, *** non-const arrays ***, structs, unions or classes ------------ and thought that was causing the problem ... It turned out that I had a line: if( result != "" ) which was causing the problem, I changed it to if( result.length > 0 ) and my function was executing at run-time now!
Feb 24 2007
parent Hasan Aljudy <hasan.aljudy gmail.com> writes:
Hasan Aljudy wrote:
 and my function was executing at run-time now!
I mean compile time ..
Feb 24 2007