To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 27114
27113  |  27115
Subject: 
Re: circular pointer
Newsgroups: 
lugnet.robotics
Date: 
Mon, 14 May 2007 05:08:00 GMT
Original-From: 
linmix <LINMIX@GMAIL.COMspamcake>
Viewed: 
5113 times
  
Dennis Williamson wrote:
In lugnet.robotics, linmix <linmix@gmail.com> wrote:
[snip]

So by defining SIZE here I can easily change the size of the macro
without having to alter anything else in the code. Nice!

[snip]

I would say defining SIZE changes the size of the array and thus the period of
the moving average. I'm not sure how you mean "macro" in this context.

I should have written: 'array'
[snip]

v[i]=0;

Is it necessary to initialise v[2] or simply 'cleaner' coding?

while (true) //** Do it forever
{
    sum -= v[i];



Yes, both necessary and cleaner. If you don't initialize v[2] then the first
statement in the while loop evaluates to "sum = sum - UNDEFINED;" which could be
anything. In many cases, it'll be zero, but it's better to be certain.

Often, variables are declared and initialized at the same time. Thus:

int i, j = 0;
int v[3] = {1, 2, 3};

OK, undefined is not the same as zero, that makes sense (in a way).
I looked up how to initialise an array and according to Dave Baum's NQC
Guide "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."
(syntax approximate)

But when using a #define or when the array is large it can work better to
initialize an array with a loop.

So indeed a loop would be the thing
Thank you for your time and detailed explanations!

Linmix



Message is in Reply To:
  Re: circular pointer
 
In lugnet.robotics, linmix <linmix@gmail.com> wrote: [snip] (...) [snip] I would say defining SIZE changes the size of the array and thus the period of the moving average. I'm not sure how you mean "macro" in this context. [snip] (...) Yes, both (...) (18 years ago, 13-May-07, to lugnet.robotics)

8 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