Jump to page: 1 2 3
Thread overview
How to printf __FILE__ ?
Mar 14, 2005
AEon
Mar 14, 2005
Andrew Fedoniouk
Mar 14, 2005
Andrew Fedoniouk
Mar 15, 2005
Walter
Mar 14, 2005
AEon
Mar 14, 2005
AEon
Mar 14, 2005
Regan Heath
Mar 15, 2005
AEon
Mar 15, 2005
Regan Heath
Mar 15, 2005
Derek Parnell
Mar 15, 2005
AEon
Mar 15, 2005
Regan Heath
Mar 15, 2005
Derek Parnell
Mar 15, 2005
AEon
Mar 15, 2005
John Reimer
Mar 15, 2005
Walter
Mar 15, 2005
John Reimer
Mar 14, 2005
Derek Parnell
March 14, 2005
How does one make the below __VAR__ info usable in some way?

---------------------------
import std.c.stdio;
// import std.file;

int main (char[][] args)
{

printf("   Testing the D Code\n");

//	test.d(9): undefined identifier __FILE__
//	make: *** [test.o] Error 1
printf("   File:		%s\n",__FILE__);
printf("   Line:		%s\n",__LINE__);
printf("   Date:		%s\n",__DATE__);
printf("   Time: 		%s\n",__TIME__);
printf("   TimeStamp:	%s\n",__TIMESTAMP__);

return 0;
}
---------------------------

Is there some place where I could look up such things. Where to ask "newbie" questions?

I am aware of http://www.digitalmars.com/d/index.html, but the docs are at times without examples.

Presently I am testing many of the things in the docs, and spamming this forum is probable not the best idea?!

AEon
March 14, 2005
AEon wrote:

> //	test.d(9): undefined identifier __FILE__
> //	make: *** [test.o] Error 1

What version of DMD are you running ?

You need DMD version 0.116 or greater:
http://www.digitalmars.com/d/changelog.html#new0116

> Is there some place where I could look up such things. Where to ask "newbie"
> questions?

We definitely need a new forum for such questions.

digitalmars.D.beginners, or something. It is bound
to get more visitors when D gets more actual users,
as opposed to fellow language hackers and lawyers ?

> I am aware of http://www.digitalmars.com/d/index.html, but the docs are at times
> without examples.

See also http://prowiki.org/wiki4d/wiki.cgi

--anders
March 14, 2005
On Mon, 14 Mar 2005 19:41:55 +0000 (UTC), AEon wrote:

> How does one make the below __VAR__ info usable in some way?
> 
> ---------------------------
> import std.c.stdio;
> // import std.file;
> 
> int main (char[][] args)
> {
> 
> printf("   Testing the D Code\n");
> 
> //	test.d(9): undefined identifier __FILE__
> //	make: *** [test.o] Error 1
> printf("   File:		%s\n",__FILE__);
> printf("   Line:		%s\n",__LINE__);
> printf("   Date:		%s\n",__DATE__);
> printf("   Time: 		%s\n",__TIME__);
> printf("   TimeStamp:	%s\n",__TIMESTAMP__);
> 
> return 0;
> }
> ---------------------------
> 
> Is there some place where I could look up such things. Where to ask "newbie" questions?
> 
> I am aware of http://www.digitalmars.com/d/index.html, but the docs are at times without examples.
> 
> Presently I am testing many of the things in the docs, and spamming this forum is probable not the best idea?!
> 
> AEon
You need to use dmd v0.116 or later, plus I'd suggest using 'writef' rather than 'printf' ...

<code>
import std.stdio;

int main (char[][] args)
{

writefln("   Testing the D Code\n");

writefln("   File:      %s",__FILE__);
writefln("   Line:      %s",__LINE__);
writefln("   Date:      %s",__DATE__);
writefln("   Time:      %s",__TIME__);
writefln("   TimeStamp: %s",__TIMESTAMP__);

return 0;
}
</code>

-- 
Derek Parnell
Melbourne, Australia
15/03/2005 7:03:41 AM
March 14, 2005
> We definitely need a new forum for such questions.
>
> digitalmars.D.beginners, or something. It is bound
> to get more visitors when D gets more actual users,
> as opposed to fellow language hackers and lawyers ?

Agreed.

digitalmars.D.howto would be better I think.

For all kind of howto's: how to compile, debug, implement, etc.

Andrew.




"Anders F Björklund" <afb@algonet.se> wrote in message news:d14q1n$2baj$1@digitaldaemon.com...
> AEon wrote:
>
>> // test.d(9): undefined identifier __FILE__
>> // make: *** [test.o] Error 1
>
> What version of DMD are you running ?
>
> You need DMD version 0.116 or greater: http://www.digitalmars.com/d/changelog.html#new0116
>
>> Is there some place where I could look up such things. Where to ask
>> "newbie"
>> questions?
>
> We definitely need a new forum for such questions.
>
> digitalmars.D.beginners, or something. It is bound
> to get more visitors when D gets more actual users,
> as opposed to fellow language hackers and lawyers ?
>
>> I am aware of http://www.digitalmars.com/d/index.html, but the docs are
>> at times
>> without examples.
>
> See also http://prowiki.org/wiki4d/wiki.cgi
>
> --anders


March 14, 2005
Andrew Fedoniouk wrote:

>> digitalmars.D.beginners, or something.

> digitalmars.D.howto would be better I think.
> 
> For all kind of howto's: how to compile, debug, implement, etc.

Hopefully those would be covered in the documentation ?

http://www.prowiki.org/wiki4d/wiki.cgi?D__Tutorial/InstallingDCompiler
http://www.prowiki.org/wiki4d/wiki.cgi?D__Tutorial/StartingWithD

Wouldn't the forum be more for: "it doesn't work! help!"

--anders
March 14, 2005
> Hopefully those would be covered in the documentation ?

Programmers (rrreal ones) do not read this stuff anyway.

BTW: Original question starts from "How to..."  so is a first candidate for howto.


"Anders F Björklund" <afb@algonet.se> wrote in message news:d14rl7$2baj$5@digitaldaemon.com...
> Andrew Fedoniouk wrote:
>
>>> digitalmars.D.beginners, or something.
>
>> digitalmars.D.howto would be better I think.
>>
>> For all kind of howto's: how to compile, debug, implement, etc.
>
> Hopefully those would be covered in the documentation ?
>
> http://www.prowiki.org/wiki4d/wiki.cgi?D__Tutorial/InstallingDCompiler http://www.prowiki.org/wiki4d/wiki.cgi?D__Tutorial/StartingWithD
>
> Wouldn't the forum be more for: "it doesn't work! help!"
>
> --anders


March 14, 2005
Anders says...

>What version of DMD are you running ?

I am running the latest Cygwin gdc 3.3.3-3 supposedly. The above did not work with DMD (also 3.3.3 AFAICT) either though.


Derek Parnell says...

> import std.stdio;

$ dmd test.d
Error: Error reading file 'std/stdio.d'

Looks like the Cgywin install is not complete?


Seems like the Cygwin distri is not as complete as it should be (or I simply forgot to install something), meaning if I want to properly code in D under windows I will need to install DMD?

Thanx for the quick help.

AEon
March 14, 2005
AEon wrote:

>>What version of DMD are you running ? 
> 
> I am running the latest Cygwin gdc 3.3.3-3 supposedly.
> The above did not work with DMD (also 3.3.3 AFAICT) either though.

Sorry, but GDC 0.10 is only like DMD 0.110

__FILE__ and $ are not available in GDC yet.

--anders

PS. The "dmd" script from the GDC distribution
    is just a "gdc" wrapper, syntax-converting
March 14, 2005
Thanx for all the feedback, I have installed DMD 0.118 and with the mentioned links, installation was no problem. The code compiles now. A few questions are still left though:

import std.c.stdio;
int main (char[][] args)
{
// DMD 0.118
// -> File:                Error: Access Violation
printf("   File:		%s\n",__FILE__);
return 0;
}

How come printf does not take __FILE__ well?

As was suggested:

import std.stdio;
int main (char[][] args)
{
writefln("   File:      %s",__FILE__);
writefln("   Line:      %s",__LINE__);
writefln("   Date:      %s",__DATE__);
writefln("   Time:      %s",__TIME__);
writefln("   TimeStamp: %s",__TIMESTAMP__);
// With DMD 0.118
//   File:      test.d
//   Line:      54
//   Date:      Mar 14 2005
//   Time:      23:12:31
//   TimeStamp: Mon Mar 14 23:12:31 2005
return 0;
}

Works just fine.

And why use writefln() (other than for the obvious reason printf crashes on the
above)? Is printf() somehow inherantly instable?

IOW what are the situtation where one should/can use printf() and when
writefln()?

Thanx.

AEon
March 14, 2005
On Mon, 14 Mar 2005 22:22:08 +0000 (UTC), AEon <AEon_member@pathlink.com> wrote:
> Thanx for all the feedback, I have installed DMD 0.118 and with the mentioned
> links, installation was no problem. The code compiles now. A few questions are
> still left though:
>
> import std.c.stdio;
> int main (char[][] args)
> {
> // DMD 0.118
> // -> File:                Error: Access Violation
> printf("   File:		%s\n",__FILE__);
> return 0;
> }
>
> How come printf does not take __FILE__ well?

I assume it's because __FILE__ is a D string, and not a null-terminated C string.

See:
http://www.prowiki.org/wiki4d/wiki.cgi?ShortFrequentAnswers

"Strings are not null-terminated but hold explicit length information. Therefore you need to use %.*s not %s in printf, or just use writef!"

Regan
« First   ‹ Prev
1 2 3