digitalmars.D.learn - module's constants and forward references
- Serg Kovrov (23/23) Jul 08 2006 Hi all,
- BCS (13/41) Jul 10 2006 First of all the is a htod program that will do a lot of the grunt work
- Serg Kovrov (12/28) Jul 10 2006 Thanks for reply.
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.
Jul 08 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;
Jul 10 2006
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.
Jul 10 2006