Jump to page: 1 2
Thread overview
Initializer lists?
Feb 25, 2004
Robert M. Münch
Feb 25, 2004
Sean Kelly
Feb 25, 2004
Manfred Nowak
Feb 25, 2004
Sean Kelly
Feb 25, 2004
Russ Lewis
Feb 25, 2004
Sean Kelly
Feb 25, 2004
Manfred Nowak
Feb 25, 2004
Russ Lewis
Feb 25, 2004
Robert M. Münch
Feb 25, 2004
Kris
Feb 25, 2004
jcc7
February 25, 2004
Hi, how can I write code like this:
	int a, b;
	a = b = 7;

This somehow doesn't work for me, I get an "no identifier for declarator" error. Robert
February 25, 2004
Robert M. Münch wrote:
>
> Hi, how can I write code like this:
>     int a, b;
>     a = b = 7;
> 
> This somehow doesn't work for me, I get an "no identifier for declarator"  error. Robert

I don't think it's legal in D.  I just checked the "expression" documentation, however, and think it may need to be revised.  There's no provision for assignments in "AssignExpression" that I can see.  Also, the "statement" documentation references it as "AssignmentExpression."


Sean

February 25, 2004
Robert M. Münch wrote:
> Hi, how can I write code like this:
>     int a, b;
>     a = b = 7;
> 
> This somehow doesn't work for me, I get an "no identifier for declarator"  error. Robert

This code compiles & runs cleanly:



int main() {
        int a,b;
        a = b = 7;
        printf("%d %d\n", a,b);
        return 0;
}

February 25, 2004
In article <opr3xj3st2heztw6@news.digitalmars.com>, =?iso-8859-1?Q?Robert_M._M=FCnch?= says...
>
>Hi, how can I write code like this:
>	int a, b;
>	a = b = 7;
>
>This somehow doesn't work for me, I get an "no identifier for declarator" error. Robert


It works for me. Try posting a full example. The problem might be elsewhere. JC

void main()
{
int a, b;
a = b = 7;
printf("%d\t%d\n", a, b);
}

/+
Output:
c:\dmd\bin\..\..\dm\bin\link.exe init2,,,user32+kernel32/noi;
7       7
+/



February 25, 2004
On Wed, 25 Feb 2004 09:13:57 -0800, Sean Kelly wrote:


> I don't think it's legal in D.
[...]

There is:

	AssignExpression:
		ConditionalExpression
		ConditionalExpression = AssignExpression

So a list of ..=..= ... = ..  is legal.

So long.
February 25, 2004
Manfred Nowak wrote:

> On Wed, 25 Feb 2004 09:13:57 -0800, Sean Kelly wrote:
> 
> 
> 
>>I don't think it's legal in D.
> 
> [...]
> 
> There is:
> 
> 	AssignExpression:
> 		ConditionalExpression
> 		ConditionalExpression = AssignExpression
> 
> So a list of ..=..= ... = ..  is legal.
> 
> So long.

But ConditionalExpression is defined thus:

ConditionalExpression:
	OrOrExpression
	OrOrExpression ? Expression : ConditionalExpression

So unless I'm reading it wrong there's so provision for a standard lvalue.  This is why I said the documentation may need revision--it wasn't clear to me whether chaines assignments should be legal or not. Especially considering what I read somewhere else in the D documentation that a programmer should never rely on a particular evaluation order (except, I assume, for logical expression short-circuiting).


Sean

February 25, 2004
Sean Kelly wrote:
> Manfred Nowak wrote:
> 
>> On Wed, 25 Feb 2004 09:13:57 -0800, Sean Kelly wrote:
>>
>>
>>
>>> I don't think it's legal in D.
>>
>>
>> [...]
>>
>> There is:
>>
>>     AssignExpression:
>>         ConditionalExpression
>>         ConditionalExpression = AssignExpression
>>
>> So a list of ..=..= ... = ..  is legal.
>>
>> So long.
> 
> 
> But ConditionalExpression is defined thus:
> 
> ConditionalExpression:
>     OrOrExpression
>     OrOrExpression ? Expression : ConditionalExpression
> 
> So unless I'm reading it wrong there's so provision for a standard lvalue.  This is why I said the documentation may need revision--it wasn't clear to me whether chaines assignments should be legal or not. Especially considering what I read somewhere else in the D documentation that a programmer should never rely on a particular evaluation order (except, I assume, for logical expression short-circuiting).
> 
> 
> Sean

ConditionalExpression expands to OrOrExpression
OrOrExpression expands to AndAndExpression

and so on, down the line to PrimaryExpression, which expands to Identifier.

So ConditionalExpression does expand to Identifier. :)

February 25, 2004
Russ Lewis wrote:
>
> ConditionalExpression expands to OrOrExpression
> OrOrExpression expands to AndAndExpression
> 
> and so on, down the line to PrimaryExpression, which expands to Identifier.
> 
> So ConditionalExpression does expand to Identifier. :)

Oops :)  I missed that first time around.  Thanks!


Sean

February 25, 2004
Sean Kelly wrote:

[...]
> that a programmer should never rely on a particular evaluation order
[...]

You are right. The evaluation order for a list of assignments ist not defined. So it is not a chain assignment.

So long.

February 25, 2004
On Wed, 25 Feb 2004 11:16:04 -0700, Russ Lewis <spamhole-2001-07-16@deming-os.org> wrote:

> This code compiles & runs cleanly:
>
> int main() {
>          int a,b;
>          a = b = 7;
>          printf("%d %d\n", a,b);
>          return 0;
> }


Ok, I had it on module level:

	module bla;

	uint a, b;
	a = b = 2*4;

This one didn't compile: "no identifier for declarator".

What I would like to do is:
	uint a = b = 2*4;

	<further code>

-- 
Robert M. Münch
Management & IT Freelancer
http://www.robertmuench.de
« First   ‹ Prev
1 2