www.digitalmars.com         C & C++   DMDScript  

D - Bug?

reply 0x4e71 <0x4e71_member pathlink.com> writes:
import std.c.stdio;
import std.string;

int main(char[][] args)
{
char[] bla = "BLA";	
printf(bla[0..1]);	
return 0;
}

Prints "BLA" . shouldn't it print "B" ?

If I replace it with printf(bla[0..1] ~ \n); 
then it is OK (it prints "B")
I am using v838

Cheers,
Luigi
Jan 25 2004
parent Vathix <vathix dprogramming.com> writes:
0x4e71 wrote:
 import std.c.stdio;
 import std.string;
 
 int main(char[][] args)
 {
 char[] bla = "BLA";	
 printf(bla[0..1]);	
 return 0;
 }
 
 Prints "BLA" . shouldn't it print "B" ?
 
 If I replace it with printf(bla[0..1] ~ \n); 
 then it is OK (it prints "B")
 I am using v838
 
 Cheers,
 Luigi
 
Not a bug. D strings aren't necessarily null-terminated. printf, being a C function, expects a null-terminated string. printf(toStringz(bla[0..1])); or printf(bla[0..1] ~ \0);
Jan 25 2004