module's constants and forward references

BCS BCS at pathlink.com
Mon Jul 10 09:34:31 PDT 2006


Serg Kovrov wrote:
> Hi all,
> 
> I'm truing to convert some c-headers, and run into problems with 
> constants in module scope.
> Here is simplified example:
> 
> ----------------------
> module test;
> import def;
> const VAL = 1;
> void main(...
> ----------------------
> module def;
> import test;
> const DVAL = VAL + 1;
> ----------------------
> 
> When I try to compile test.d, i've got:
> "def.d(5): forward reference of VAL"
> But if I use int instead of const, everything compiles as expected. 
> Could someone explain why the difference and how to have it as constants 
> (as they was #define'd in c-header files)?
> 
> Thanks.
> 
> PS dmd v0.162
> -- 
> Serg.

First of all the is a htod program that will do a lot of the grunt work 
for you.

http://www.digitalmars.com//d/htod.html

Second a solution:

module test;
import def;
const int VAL = 1;
void main(...
----------------------
module def;
import test;
const int DVAL = VAL + 1;



More information about the Digitalmars-d-learn mailing list