www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Structure property bug?

reply Todd <toddtitus mindspring.com> writes:
I'm using DFL w/DMD ver 1.020 and receive the following compile 
error's: 

no property 'Data' for type 'ARINCDATA_CELL [51u]' 
ArincWord is not an lvalue 
ReceivedChannel is not an lvalue 
Returned status code 1 

Code: 

alias uint ArincWord; 
alias uint TimeRead; 
alias short ReceivedChannel; 

struct ARINCDATA_CELL 
{ 
  align(1): 
    short Channel; 
    uint Time; 
    uint Data; 
} 
. 
. 
. 
ARINCDATA_CELL ArincData[51]; 
. 
. 
if(ArincData.Data &0xff == 203) 
{ 
  ArincWord       = ArincData[i].Data; 
  ReceivedChannel = ArincData[i].Channel; 
} 
. 
. 
. 
Tried everything I could think of but no dice. 
Think its related to the "[51]" or a bug. I've seen this error 
posted in the past, however none of the solutions seem to work, 
unless I missed one somewhere? 

Any idea's? 

Todd 


 
Oct 04 2007
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
"Todd" wrote
 I'm using DFL w/DMD ver 1.020 and receive the following compile
 error's:

 no property 'Data' for type 'ARINCDATA_CELL [51u]'
 ArincWord is not an lvalue
 ReceivedChannel is not an lvalue
 Returned status code 1

 Code:

 alias uint ArincWord;
 alias uint TimeRead;
 alias short ReceivedChannel;

 struct ARINCDATA_CELL
 {
  align(1):
    short Channel;
    uint Time;
    uint Data;
 }
 .
 .
 .
 ARINCDATA_CELL ArincData[51];
 .
 .
 if(ArincData.Data &0xff == 203)
 {
  ArincWord       = ArincData[i].Data;
  ReceivedChannel = ArincData[i].Channel;
 }
 .
 .
 .
 Tried everything I could think of but no dice.
 Think its related to the "[51]" or a bug. I've seen this error
 posted in the past, however none of the solutions seem to work,
 unless I missed one somewhere?

 Any idea's?

This works. I think you have a few syntax errors: if(ArincData[i].Data &0xff == 203) { ArincWord v1 = ArincData[i].Data; ReceivedChannel v2= ArincData[i].Channel; } Note the [i] in the if statement, and the variable names v1 and v2. -Steve
Oct 04 2007
next sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
"Steven Schveighoffer" wrote
  if(ArincData[i].Data &0xff == 203)

I just realized also that assuming D has the same operator precedence as C/C++, this really evalulates as: if(ArincData[i].Data & (0xff == 203)) Which will obviously be compiled out. So what you really want is: if((ArincData[i].Data & 0xff) == 203) BTW, I looked through the entire spec, and cannot find operator precedence anywhere. Anyone know where it is? -Steve
Oct 04 2007
next sibling parent reply Regan Heath <regan netmail.co.nz> writes:
Steven Schveighoffer wrote:
 BTW, I looked through the entire spec, and cannot find operator precedence 
 anywhere.  Anyone know where it is?

It's not ideal but you can figure out precedence by looking at: http://www.digitalmars.com/d/expression.html The first operator mentioned is , and it has the lowest precedence (due to how the syntax tree is parsed - I think). regan
Oct 04 2007
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
"Regan Heath" wrote
 Steven Schveighoffer wrote:
 BTW, I looked through the entire spec, and cannot find operator 
 precedence anywhere.  Anyone know where it is?

It's not ideal but you can figure out precedence by looking at: http://www.digitalmars.com/d/expression.html The first operator mentioned is , and it has the lowest precedence (due to how the syntax tree is parsed - I think).

I think you are right about this, but it is VERY subtle. I had to read it for about 20 minutes before I understood what you are talking about. It would be nice to have a table at the end, which summarizes the precedence. Walter? -Steve
Oct 04 2007
parent reply Regan Heath <regan netmail.co.nz> writes:
Steven Schveighoffer wrote:
 "Regan Heath" wrote
 Steven Schveighoffer wrote:
 BTW, I looked through the entire spec, and cannot find operator 
 precedence anywhere.  Anyone know where it is?

http://www.digitalmars.com/d/expression.html The first operator mentioned is , and it has the lowest precedence (due to how the syntax tree is parsed - I think).

I think you are right about this, but it is VERY subtle. I had to read it for about 20 minutes before I understood what you are talking about. It would be nice to have a table at the end, which summarizes the precedence. Walter?

http://www.digitalmars.com/d/archives/12484.html <g> Regan
Oct 04 2007
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
"Regan Heath" wrote
 http://www.digitalmars.com/d/archives/12484.html

 <g>

Hm... I guess we know Walter's opinion :) If it's just a question of not having time to do the table, would it be possible for someone to write one and submit it for Walter to include? Because telling someone to manually parse the grammar to me is like telling someone to go read the compiler code to figure out the precedence. I know a lot of good coders who don't necessarily read language grammar specs. Even I, who understood generally what the grammar spec means, didn't get that the operator precedence was "hidden" in the grammar. I generally ignore the grammar boxes and just read the english descriptions/examples. -Steve
Oct 04 2007
parent reply Regan Heath <regan netmail.co.nz> writes:
Steven Schveighoffer wrote:
 "Regan Heath" wrote
 http://www.digitalmars.com/d/archives/12484.html

 <g>

Hm... I guess we know Walter's opinion :) If it's just a question of not having time to do the table, would it be possible for someone to write one and submit it for Walter to include? Because telling someone to manually parse the grammar to me is like telling someone to go read the compiler code to figure out the precedence. I know a lot of good coders who don't necessarily read language grammar specs. Even I, who understood generally what the grammar spec means, didn't get that the operator precedence was "hidden" in the grammar. I generally ignore the grammar boxes and just read the english descriptions/examples.

I think that's a good idea, the most likely to see results any time soon. I suspect operator precedence in D is almost identical to C/C++ so I'd start by copying a table for C/C++, eg. (a quick google) http://www.difranco.net/cop2220/op-prec.htm Regan
Oct 04 2007
parent James Dennett <jdennett acm.org> writes:
Regan Heath wrote:
 Steven Schveighoffer wrote:
 "Regan Heath" wrote
 http://www.digitalmars.com/d/archives/12484.html

 <g>

Hm... I guess we know Walter's opinion :) If it's just a question of not having time to do the table, would it be possible for someone to write one and submit it for Walter to include? Because telling someone to manually parse the grammar to me is like telling someone to go read the compiler code to figure out the precedence. I know a lot of good coders who don't necessarily read language grammar specs. Even I, who understood generally what the grammar spec means, didn't get that the operator precedence was "hidden" in the grammar. I generally ignore the grammar boxes and just read the english descriptions/examples.

I think that's a good idea, the most likely to see results any time soon. I suspect operator precedence in D is almost identical to C/C++ so I'd start by copying a table for C/C++, eg. (a quick google) http://www.difranco.net/cop2220/op-prec.htm

Operator precendence for C++ cannot be (correctly) expressed in a linear table; a grammar is the simplest way to capture it accurately. (That may not be true for D, which has been able to keep many things simpler.) -- James
Oct 04 2007
prev sibling parent Todd <toddtitus mindspring.com> writes:
Steven Schveighoffer Wrote:

 "Steven Schveighoffer" wrote
  if(ArincData[i].Data &0xff == 203)

I just realized also that assuming D has the same operator precedence as C/C++, this really evalulates as: if(ArincData[i].Data & (0xff == 203)) Which will obviously be compiled out. So what you really want is: if((ArincData[i].Data & 0xff) == 203) BTW, I looked through the entire spec, and cannot find operator precedence anywhere. Anyone know where it is? -Steve

That works perfect, funny how everything gets blurry at the end of the day. Todd
Oct 04 2007
prev sibling parent "Janice Caron" <caron800 googlemail.com> writes:
On 10/5/07, James Dennett <jdennett acm.org> wrote:
 Operator precendence for C++ cannot be (correctly) expressed
 in a linear table

Ooh, now that's an interesting statement! Why not?
Oct 05 2007