Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 07, 2007 std/c/time.d const sysconf bug? | ||||
---|---|---|---|---|
| ||||
$ 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? |
January 07, 2007 Re: std/c/time.d const sysconf bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dawid Ciężarkiewicz Attachments: | 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 |
January 07, 2007 Re: std/c/time.d const sysconf bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Kuehne | 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...
|
January 08, 2007 Re: std/c/time.d const sysconf bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frits van Bommel | 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? :)
|
Copyright © 1999-2021 by the D Language Foundation