To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.nxtOpen lugnet.robotics.nxt in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / NXT / 688
687  |  689
Subject: 
Re: NBC/NXC beta news
Newsgroups: 
lugnet.robotics.nxt
Date: 
Wed, 25 Apr 2007 22:51:01 GMT
Viewed: 
18174 times
  
In lugnet.robotics.nxt, John Hansen wrote:
In lugnet.robotics.nxt, Doug Eaton wrote:
Is an array of struct expected to work?  When I try to access a field within an
element I get an error:

# Error: parser error
File "test.nxc" ; line 217
#    val=cell[index].b
#----------------------------------------------------------
# Error: ')' expected

Of note, the field name is truncated to the first character in the error.

The problem with code of this sort is that the opcodes for manipulating values
do not readily allow for this type of operation. To set the variable val to the
value of the bxxx field of the structure type stored in your array of structs I
ultimately need to generate a mov opcode.

mov val, somevariablename

The VM doesn't have variants of the mov opcode which allow for offsets or
indirects of any sort.  So I would need to generate code which copies out
cell[index] into a temporary variable of the correct structure type and then I
would need to generate the mov opcode using the temporary variable.  I'd need at
least one unique temporary for each thread and each structure type.  Not
impossible but rather complicated.  The workaround is to simply declare a
variable explicitly of the correct structure type and set it to cell[index] then
set val in a second statement.

Well that technique does compile, but produces interesting results:

---
#include "NXCDefs.h"

struct st
{
  string s1;
  int i1;
}

st a1[];
st v1,v2;

task main()
{
  v1.s1 = "test";
  v1.i1 = 9;
  NumOut(0,0,v1.i1);
  TextOut(40,0,v1.s1);
  ArrayInit(a1,v1,2);
  v2 = a1[1];
  NumOut(0,8,v1.i1);
  TextOut(40,8,v1.s1);
  NumOut(0,16,v2.i1);
  TextOut(40,16,v2.s1);
  Wait(2000);
}
---

ROSCO



Message has 1 Reply:
  Re: NBC/NXC beta news
 
(...) Sorry for not getting back with you sooner about this bug, Rosco. Life comes at you fast, as they say. :-) I investigated this problem today and it looks like I've got it fixed. There were several bugs going on in NBC which were causing the (...) (18 years ago, 28-Apr-07, to lugnet.robotics.nxt)

Message is in Reply To:
  Re: NBC/NXC beta news
 
(...) The problem with code of this sort is that the opcodes for manipulating values do not readily allow for this type of operation. To set the variable val to the value of the bxxx field of the structure type stored in your array of structs I (...) (18 years ago, 25-Apr-07, to lugnet.robotics.nxt)

7 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR