Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-20-2007, 10:50 PM
littlevamp littlevamp is offline
Newbie
 
Join Date: Sep 2007
Posts: 5
Rep Power: 0
littlevamp is on a distinguished road
Default Implicit declaration of set_timer

Hi,

I was hoping that someone can help me with this. When I ran the below codes, it stated that there is an implicit declaration of set_timer in line 6. But my set_timer function has already been declared after the main(). Why is this so?

C Code:
  1. #include<stdio.h>
  2. #include<sys/time.h>
  3. #include<signal.h>
  4. #include<unistd.h>
  5. int main() {
  6.   if(set_ticker(500) == -1)
  7.     perror("set_ticker");
  8.   else
  9.     while(1) pause();
  10.   return 0;
  11. }
  12.  
  13. int set_ticker(int n_msecs) {
  14.   struct itimerval new_timeset;
  15.   long n_sec, n_usecs;
  16.   n_sec = (n_msecs/1000);                     
  17.   n_usecs = (n_msecs % 1000) * 1000L;         
  18.   new_timeset.it_interval.tv_set = n_sec;   
  19.   new_timeset.it_interval.tv_usec = n_usecs;
  20.   new_timeset.it_value.tv_sec = n_sec;     
  21.   new_timeset.it_value.tv_usec = n_usecs;     
  22.   return setitimer(ITIMER_REAL, &new_timeset, NULL);
  23. }

Will appreciate help, thanks in advance!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-21-2007, 02:12 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

When you're making the implementation of the function after main(), you've to have a declaration before main() If you don't have that, it can't find the function inside main()

Code:
// This should be before main()
int set_ticker(int n_msecs);
I can't test your code, I'm on Windows, but I think it would work.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-21-2007, 10:42 AM
littlevamp littlevamp is offline
Newbie
 
Join Date: Sep 2007
Posts: 5
Rep Power: 0
littlevamp is on a distinguished road
Default

Thanks =)

The codes run well.

C Code:
  1. struct itimerval new_timeset;
  2. long n_sec, n_usecs;
  3. n_sec = n_msecs/1000;                     
  4. n_usecs = (n_msecs % 1000) * 1000L;         
  5. new_timeset.it_interval.tv_set = n_sec;

However, there is some problem with this line: new_timeset.it_interval.tv_set = n_sec. There is this error: struct timeval has no member named tv_set. What is this error about?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-21-2007, 11:17 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

The error is exactly about what it's saying. The struct "timeval" do not have a member called "tv_set." I can't help you on this one, because it's Linux-specific. Look up the documentations, and you'll probably find something useful.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -5. The time now is 03:11 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads