Thread overview | |||||
---|---|---|---|---|---|
|
July 09, 2006 module's constants and forward references | ||||
---|---|---|---|---|
| ||||
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. |
July 10, 2006 Re: module's constants and forward references | ||||
---|---|---|---|---|
| ||||
Posted in reply to Serg Kovrov | 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; |
July 10, 2006 Re: module's constants and forward references | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | Hi BCS, you wrote:
>
> 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;
Thanks for reply.
Yes, I noticed when type defined explicitly, it works. It seems omitting constants type in declaration is same as 'auto' declaration. Which seems does not works for forward declaration.
And yes, I use htod tool, but still there is lot of manual work.
PS. I'm trying to translate OpenSSL headers. There are lot of nasty macro stuff, but it seems it used mostly internally. Is far as I know there is no OpenSSL bindings yet. When/if I make some progress with working sample, I'll expose code.
--
serg.
|
Copyright © 1999-2021 by the D Language Foundation