www.digitalmars.com         C & C++   DMDScript  

D - Initializer lists?

reply "=?iso-8859-1?Q?Robert_M._M=FCnch?=" <robert.muench robertmuench.de> writes:
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
Feb 25 2004
next sibling parent reply Sean Kelly <sean ffwd.cx> writes:
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
Feb 25 2004
parent reply Manfred Nowak <svv1999 hotmail.com> writes:
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.
Feb 25 2004
parent reply Sean Kelly <sean ffwd.cx> writes:
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
Feb 25 2004
next sibling parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
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. :)
Feb 25 2004
parent Sean Kelly <sean ffwd.cx> writes:
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
Feb 25 2004
prev sibling parent Manfred Nowak <svv1999 hotmail.com> writes:
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.
Feb 25 2004
prev sibling next sibling parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
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; }
Feb 25 2004
parent reply "=?iso-8859-1?Q?Robert_M._M=FCnch?=" <robert.muench robertmuench.de> writes:
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
Feb 25 2004
parent "Kris" <someidiot earthlink.net> writes:
I believe you can achieve the same result (at the module level) via a static
constructor.

- Kris

"Robert M. Münch" <robert.muench robertmuench.de> wrote in message
news:opr3x69qshheztw6 news.digitalmars.com...
 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
Feb 25 2004
prev sibling parent jcc7 cox.net writes:
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 +/
Feb 25 2004