www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - const { ... } no workie?

reply AEon <AEon_member pathlink.com> writes:
// Const Attribute example from manual
(http://www.prowiki.org/wiki4d/wiki.cgi?LanguageSpecification/Original)

const int foo = 7;

const
{ // Line 183
double bar = foo + 6;
}

// test.d(183): basic type expected, not {
// test.d(183): no identifier for declarator int
// test.d(183): semicolon expected, not '{'
// --- errorlevel 1	


Is the const { } syntax not yet implemented in dmd 0.118, or did I miss
something?

AEon
Mar 15 2005
next sibling parent reply Manfred Nowak <svv1999 hotmail.com> writes:
AEon <AEon_member pathlink.com> wrote:

[...]
 // test.d(183): basic type expected, not {

Not confirmed. dmd 0.118 compiles the example lines. -manfred
Mar 15 2005
parent reply AEon <AEon_member pathlink.com> writes:
Manfred Nowak says...

AEon wrote:
[...]
 // test.d(183): basic type expected, not {

Not confirmed. dmd 0.118 compiles the example lines.

Could it be that I am doing something wrong with the compile options? dmd -c -w -O -release -inline -I. test.d AEon
Mar 15 2005
parent reply "Ben Hinkle" <bhinkle mathworks.com> writes:
posting a complete example would help. It works fine for me, too, no matter 
what options I throw at the compiler.

"AEon" <AEon_member pathlink.com> wrote in message 
news:d16ts4$1db5$1 digitaldaemon.com...
 Manfred Nowak says...

AEon wrote:
[...]
 // test.d(183): basic type expected, not {

Not confirmed. dmd 0.118 compiles the example lines.

Could it be that I am doing something wrong with the compile options? dmd -c -w -O -release -inline -I. test.d AEon

Mar 15 2005
next sibling parent reply AEon <AEon_member pathlink.com> writes:
Ben Hinkle says...

posting a complete example would help. It works fine for me, too, no matter 
what options I throw at the compiler.

Right, I had the example running with several other examples as well, now I placed the example in a seperat file: consttest.d <code> import std.c.stdio; int main (char[][] args) { // Const Attribute example from manual const int foo = 7; const { // Line 10 double bar = foo + 6; } return 0; } </code> I still get the same error in line 10 though:
dmd consttest.d

consttest.d(10): no identifier for declarator int consttest.d(10): semicolon expected, not '{' Hope that helps. AEon
Mar 15 2005
parent reply clayasaurus <clayasaurus gmail.com> writes:
AEon wrote:
 Ben Hinkle says...
 
 
posting a complete example would help. It works fine for me, too, no matter 
what options I throw at the compiler.

Right, I had the example running with several other examples as well, now I placed the example in a seperat file: consttest.d <code> import std.c.stdio; int main (char[][] args) { // Const Attribute example from manual const int foo = 7; const { // Line 10 double bar = foo + 6; } return 0; } </code> I still get the same error in line 10 though:
dmd consttest.d

consttest.d(10): basic type expected, not { consttest.d(10): no identifier for declarator int consttest.d(10): semicolon expected, not '{' Hope that helps. AEon

(dmd .118 linux) I get the same errors. Why not just use const double bar = foo + 6;
Mar 15 2005
parent AEon <AEon_member pathlink.com> writes:
In article <d17br2$1tt6$1 digitaldaemon.com>, clayasaurus says...

(dmd .118 linux)
I get the same errors. Why not just use
const double bar = foo + 6;

/me (dmd .118 windows) Actually I don't really have a problem with the above, just surprised my that the compile test failed. Well at least on my setup. AEon
Mar 15 2005
prev sibling parent reply randomnewbie <bob bob.com> writes:
Ben Hinkle wrote:
 posting a complete example would help. It works fine for me, too, no matter 
 what options I throw at the compiler.
 
 "AEon" <AEon_member pathlink.com> wrote in message 
 news:d16ts4$1db5$1 digitaldaemon.com...
 
Manfred Nowak says...


AEon wrote:
[...]

// test.d(183): basic type expected, not {

[...] Not confirmed. dmd 0.118 compiles the example lines.

Could it be that I am doing something wrong with the compile options? dmd -c -w -O -release -inline -I. test.d AEon


you can use const with D?
Mar 15 2005
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"randomnewbie" <bob bob.com> wrote in message 
news:d178dn$1q21$1 digitaldaemon.com...

 you can use const with D?

Yes, just not in all the ways that you can in C++. C++ allows you to, for example, declare function parameters as const, thus making them unmodifyable. D doesn't. However, const variable declarations are allowed.
Mar 15 2005
prev sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
AEon wrote:
 // Const Attribute example from manual
 (http://www.prowiki.org/wiki4d/wiki.cgi?LanguageSpecification/Original)
 
 const int foo = 7;
 
 const
 { // Line 183
 double bar = foo + 6;
 }
 
 // test.d(183): basic type expected, not {
 // test.d(183): no identifier for declarator int
 // test.d(183): semicolon expected, not '{'
 // --- errorlevel 1	
 
 
 Is the const { } syntax not yet implemented in dmd 0.118, or did I miss
 something?

Yes. That the code snippet on that page isn't within a function. The attribute { ... } syntax applies at only module or class/struct/union level. But there does seem to be something missing from the spec here.... Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jun 21 2005