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 / 27113
27112  |  27114
Subject: 
Re: circular pointer
Newsgroups: 
lugnet.robotics
Date: 
Sun, 13 May 2007 20:41:57 GMT
Viewed: 
5100 times
  
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.

[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};

(syntax approximate)

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

Dennis



Message has 1 Reply:
  Re: circular pointer
 
(...) I should have written: 'array' (...) 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 (...) (18 years ago, 14-May-07, to lugnet.robotics)

Message is in Reply To:
  Re: circular pointer
 
I've inserted some comments, not all are questions, some are simply 'thinking aloud'. (...) So by defining SIZE here I can easily change the size of the macro without having to alter anything else in the code. Nice! (...) Right you are, I should (...) (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

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