To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1795
1794  |  1796
Subject: 
Re: Arrays and functions in NQC
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Thu, 8 Sep 2005 12:40:47 GMT
Viewed: 
6291 times
  
In lugnet.robotics.rcx.nqc, Philippe Hurbain wrote:
Two little questions for the NQC gurus...

- Is it possible to use 2-dimentionnal arrays in NQC?
- Is it possible (and if yes what is the syntax) to pass an array as an inline
function parameter?


No.  No.

From the NQC Guide:

The RCX2, Swan, and Spybotics targets support arrays (the other targets do not
have suitable support in firmware for arrays). Arrays are declared the same way
as ordinary variables, but with the size of the array enclosed in brackets. The
size must be a constant.

int my_array[3]; // declare an array with three elements

The elements of an array are identified by their position within the array
(called an index). The first element has an index of 0, the second has index 1,
etc. For example:

my_array[0] = 123; // set first element to 123

my_array[1] = my_array[2]; // copy third into second

Currently there are a number of limitations on how arrays can be used. These
limitations will likely be removed in future versions of NQC:

· An array cannot be an argument to a function. An individual array element, however, can be passed to a function.

· Neither arrays nor their elements can be used with the increment (++) or decrement (--) operators.

· The initial values for an array's elements cannot be specified - an explicit assignment is required within the program itself to set the value of an element.


You can, however, use pointers in NQC.

#pragma noinit

int data[20]; // block of memory
int * ptr;

void MyFunc(int* x, int & val)
{
  *x = val;

}

task main()
{
  ptr = &data[0];
  int i;
  for(i=0; i < 20; i++)
  {
    MyFunc(ptr, i);
    ptr++;
  }
}


You can use pointers to implement something like a two dimensional array.

John Hansen



Message is in Reply To:
  Arrays and functions in NQC
 
Two little questions for the NQC gurus... - Is it possible to use 2-dimentionnal arrays in NQC? - Is it possible (and if yes what is the syntax) to pass an array as an inline function parameter? TIA, Philo (19 years ago, 8-Sep-05, to lugnet.robotics.rcx.nqc)

2 Messages in This Thread:

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

Custom Search

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