std/c/time.d const sysconf bug?

Thomas Kuehne thomas-dloop at kuehne.cn
Sun Jan 7 08:57:30 PST 2007


-----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-----


More information about the Digitalmars-d-bugs mailing list