Thread overview
const { ... } no workie?
Mar 15, 2005
AEon
Mar 15, 2005
Manfred Nowak
Mar 15, 2005
AEon
Mar 15, 2005
Ben Hinkle
Mar 15, 2005
AEon
Mar 15, 2005
clayasaurus
Mar 15, 2005
AEon
Mar 15, 2005
randomnewbie
Jun 21, 2005
Stewart Gordon
March 15, 2005
// 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
March 15, 2005
AEon <AEon_member@pathlink.com> wrote:

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

Not confirmed. dmd 0.118 compiles the example lines.

-manfred
March 15, 2005
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
March 15, 2005
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


March 15, 2005
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
March 15, 2005
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?
March 15, 2005
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;
March 15, 2005
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
March 15, 2005
"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.


June 21, 2005
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.