CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

function not void and does not return a value

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
shapito



Joined: 21 Feb 2012
Posts: 9

View user's profile Send private message Send e-mail

function not void and does not return a value
PostPosted: Thu Mar 22, 2012 10:39 am     Reply with quote

can somebody help me.why when I compile this program, error was shown.

#include <16F876A.h>
#device ICD=TRUE
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#include <can-18xxx8.c>

#define GREEN_LED PIN_A5
#define YELLOW_LED PIN_B4
#define RED_LED PIN_B1
#define PUSH_BUTTON PIN_A4

light_one_led(int led) {
output_high(GREEN_LED);
output_high(YELLOW_LED);
output_high(RED_LED);
switch(led){
case 0 : output_low(GREEN_LED); break;
case 1 : output_low(YELLOW_LED); break;
case 2 : output_low(RED_LED); break;
}
}

wait_for_one_press() {
while(input(PUSH_BUTTON));
while(!input(PUSH_BUTTON));
}

void main(){
while(TRUE) {
light_one_led(0);
wait_for_one_press();
light_one_led(1);
wait_for_one_press();
light_one_led(2);
wait_for_one_press();
}
}

it said "function not void and does not return a value light_one_led" and
"function not void and does not return a value wait_for_one_press".
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Thu Mar 22, 2012 10:45 am     Reply with quote

If I remember rightly, in C subroutines not explicitly given a return type are assumed to be functions returning int. Try:

Code:

void light_one_led(int led) {
    output_high(GREEN_LED);
    output_high(YELLOW_LED);
    output_high(RED_LED);
    switch(led){
        case 0 : output_low(GREEN_LED); break;
        case 1 : output_low(YELLOW_LED); break;
        case 2 : output_low(RED_LED); break;
    }
}


...and please use the
Code:
blah
formatting to display code.

RF Developer
shapito



Joined: 21 Feb 2012
Posts: 9

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 22, 2012 11:10 am     Reply with quote

thanx..its working...but the code "blah" i still confused where to put it..
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Mar 22, 2012 1:39 pm     Reply with quote

shapito wrote:
thanx..its working...but the code "blah" i still confused where to put it..
What we mean is that your posted source code is more readable when you use the special code formatting tags from this forum. For more info read http://www.sitepoint.com/forums/misc.php?do=bbcode. The code tag is described half way down the page.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Thu Mar 22, 2012 2:18 pm     Reply with quote

You're also going to find that your routine to wait for the button press then wait for it not pressed has a "minor" flaw - if your pushbutton bounces like most do, then it will go through there as many times as it bounces. Probably not an issue here, but something to be aware of when you expect a single "press" to do something only once.

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group