www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - std/c/time.d const sysconf bug?

reply Dawid =?UTF-8?B?Q2nEmcW8YXJraWV3aWN6?= <dawid.ciezarkiewicz asn.pl> writes:
$ dmd
Digital Mars D Compiler v1
...


$ make
+ /home/dpc/stg/d/bin/dsss_build -I/home/dpc/stg/d/include/d
-LIBPATH=/home/dpc/stg/d/lib/ -LIBPATH=./  -od. 
server.d -Tserver
/home/dpc/stg/d/include/d/std/c/time.d(40): Error: non-constant expression
(sysconf)(2)

else version (linux)
{
    extern (C) int sysconf(int);
    const clock_t CLK_TCK = cast(clock_t) sysconf(2); // <---------- THIS
}


How can THIS be a const, hmm?
Jan 07 2007
parent reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dawid Ci??arkiewicz schrieb am 2007-01-07:
 $ dmd
 Digital Mars D Compiler v1
 ...


 $ make
 + /home/dpc/stg/d/bin/dsss_build -I/home/dpc/stg/d/include/d
-LIBPATH=/home/dpc/stg/d/lib/ -LIBPATH=./  -od. 
 server.d -Tserver
 /home/dpc/stg/d/include/d/std/c/time.d(40): Error: non-constant expression
 (sysconf)(2)

 else version (linux)
 {
     extern (C) int sysconf(int);
     const clock_t CLK_TCK = cast(clock_t) sysconf(2); // <---------- THIS
 }

Please replace the line with: clock_t CLK_TCK(){ return cast(clock_t) sysconf(2); } Using "static this" would work for common use-cases but not if running applications are beeing migrated between different systems.
 How can THIS be a const, hmm?

D's const isn't exactly Java's const ... http://www.digitalmars.com/d/attribute.html#const # # The const attribute declares constants that can be evaluated at # compile time. # sounds good, but # # A const declaration without an initializer must be initialized in a # constructor (for class fields) or in a static constructor (for static # class members, or module variable declarations). # Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFoTJrLK5blCcjpWoRAst2AJ9dHVqnmfr9SJ50Dn33jaum0+kdWwCgpwtQ mt5d7tOj6i/8dveIX77ZAo8= =7oOu -----END PGP SIGNATURE-----
Jan 07 2007
parent reply Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Thomas Kuehne wrote:
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 Dawid Ci??arkiewicz schrieb am 2007-01-07:
 $ dmd
 Digital Mars D Compiler v1
 ...


 $ make
 + /home/dpc/stg/d/bin/dsss_build -I/home/dpc/stg/d/include/d
-LIBPATH=/home/dpc/stg/d/lib/ -LIBPATH=./  -od. 
 server.d -Tserver
 /home/dpc/stg/d/include/d/std/c/time.d(40): Error: non-constant expression
 (sysconf)(2)

 else version (linux)
 {
     extern (C) int sysconf(int);
     const clock_t CLK_TCK = cast(clock_t) sysconf(2); // <---------- THIS
 }

Please replace the line with: clock_t CLK_TCK(){ return cast(clock_t) sysconf(2); } Using "static this" would work for common use-cases but not if running applications are beeing migrated between different systems.

My first instinct when I read that message was to post just such a reply, but then I noticed he wasn't talking about his own code. This is in Phobos's std.c.time module...
Jan 07 2007
parent Dawid =?UTF-8?B?Q2nEmcW8YXJraWV3aWN6?= <dawid.ciezarkiewicz asn.pl> writes:
Frits van Bommel wrote:
 Please replace the line with:
 clock_t CLK_TCK(){ return cast(clock_t) sysconf(2); }
 
 Using "static this" would work for common use-cases but not if
 running applications are beeing migrated between different systems.

My first instinct when I read that message was to post just such a reply, but then I noticed he wasn't talking about his own code. This is in Phobos's std.c.time module...

Yes indeed. This is D.bug, not D.learn, right? :)
Jan 08 2007