Several segmentation faults

Lars public at kyllingen.net
Thu May 29 03:05:52 PDT 2008


Josh Wrote:

> Has anyone had segmentation faults running the tutorials?  This segfaults on my computer (Ubuntu 8.04) using dgc.  It's taken from one of the tutorials, but several similar tutorials also fail.  
> 
> import std.stdio;
> 
> int magicNumber = 42;
> char[] password = "sesame";
> 
> void main() {
>   writefln("Magic number: ", magicNumber);
>   writefln("Password: ", password);
> }

I was searching for the answer to the exact same question. It seems that writef and writefln segfault whenever additional arguments are passed. Consider the following (modified) Hello World:

  import std.stdio;

  void main {
      writefln("Hello %s!", "world");
  }

When I compile this on my system (also running Ubuntu 8.04) with GDC and run it, it immediately segfaults without displaying the message. Just using

  writefln("Hello world!");

works perfectly, however. Some more testing shows that writing to other streams (files, etc.) doesn't work either. The printf() function works fine.

Something wrong with the newest Ubuntu build of GDC, then? I tried running my hello-world program through GDB, this is the output I got:

Starting program: /home/lars/development/programming/d/test/helloworld 
[Thread debugging using libthread_db enabled]
[New Thread 0x7f0871deb6e0 (LWP 16622)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f0871deb6e0 (LWP 16622)]
0x000000000040cfe9 in _D3std6format11doFormatPtrFDFwZvAC8TypeInfoG1S6object13__va_list_tagPvZv9formatArgMFaZv6putstrMFAaZv ()
Current language:  auto; currently asm


Regards,
Lars



More information about the Digitalmars-d mailing list