To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.handyboardOpen lugnet.robotics.handyboard in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / Handy Board / 7061
7060  |  7062
Subject: 
Re: IC trouble - function definition
Newsgroups: 
lugnet.robotics.handyboard
Date: 
Sat, 13 Nov 1999 14:04:32 GMT
Original-From: 
John Bachman <BACHMAN@ANATEK.MV.COMavoidspam>
Viewed: 
630 times
  
Thanks for all the helpful device but the darned thing still does not work.  I have created a simplified program to try to figure out what I am doing wrong.  Here it is:

/* A simplified program to figure out what is wrong */

long time;

void start()
{
       phony();

       void phony() /*  Line 9 syntax error is reported here */
       {
       while (digital(2) == 1)
                      {
time = mseconds();
}
       }
}

When I try to load it with IC I get a syntax error on line 9.  Can anyone tell me why?

TIA


At 03:41 PM 11/12/99 -0800, you wrote:
    John:

    If your function does not need a parameter passed to it
    just do:

    void detect_time2()
    {
    /* code here */
    }

    just like
    int main()
    {
    /* code here */
    }

    Bart.


______________________________ Reply Separator
_________________________________
Subject: IC trouble - function definition
Author:  Non-HP-bachman (bachman@anatek.mv.com) at HP-PaloAlto,mimegw2
Date:    11/12/99 11:44 AM


I am having trouble with function definitions.  Can someone tell me what is
wron
g with this:

void detect_time_2 (void)
       { code here;}

I get a syntax error on the definition line and cannot figure out why.

TIA

John




Message has 3 Replies:
  Re: IC trouble - function definition
 
[John Bachman] spake unto the ether: (...) You have the definition of phony() nested inside the definition of start(). I don't know what ANSI C and/or C++ let you do, but this is invalid IC. You need something like: long time; void start() { (...) (25 years ago, 13-Nov-99, to lugnet.robotics.handyboard)
  Re: IC trouble - function definition
 
(...) whoa! Local function definitions. Even GCC doesn't grok that. Try extracting the function definition phony() from start() like so: long time; void phony() { while (digital(2) == 1) { time = mseconds(); } } void start() { phony(); } -d (...) (25 years ago, 13-Nov-99, to lugnet.robotics.handyboard)
  Re: IC trouble - function definition - understand now, Thanks
 
Rich got it. Nested functions was the problem. I don't recall seeing that discussed in the IC manual and I think it is OK in C. Nonetheless, thanks to all for helping this hapless programmer. John (...) (25 years ago, 13-Nov-99, to lugnet.robotics.handyboard)

Message is in Reply To:
  IC trouble - function definition
 
I am having trouble with function definitions. Can someone tell me what is wrong with this: void detect_time_2 (void) { code here;} I get a syntax error on the definition line and cannot figure out why. TIA John (25 years ago, 12-Nov-99, to lugnet.robotics.handyboard)

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