Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C++ compile error

  • 24-01-2008 11:13am
    #1
    Registered Users, Registered Users 2 Posts: 357 ✭✭


    Trying to compile this code on ubuntu with g++. Getting these errors.

    utime.cpp: In function ‘int main(int, char**)’:
    utime.cpp:27: error: ‘exit’ was not declared in this scope
    utime.cpp:35: error: ‘atoi’ was not declared in this scope
    utime.cpp:57: error: ‘usleep’ was not declared in this scope

    Can anyone see where I might be going wrong?
    Cheers for any help.
    #include<stdio.h>
    
    #include<time.h>
    
    #include <sys/time.h>
    
    #include <sys/resource.h>
    
     
    
    int main(int argc, char** argv){
    
     
    
    struct  timeval tv;
    
    struct  timezone tz;
    
    int i,delay,num_iter;
    
     double init,start,stop;
    
    if (argc!=3) {
    
        fprintf(stderr, "Usage: %s <sleep time..usec><num_iteration>\n", argv[0]);
    
        exit(1);
    
      }
    
     
    
    //  progname=argv[0];
    
      delay=atoi(argv[1]);
    
      num_iter=atoi(argv[2]);
    
      printf("Delay is %d usec..num_iter is %d\n",delay,num_iter);
    
      gettimeofday( &tv,&tz);
    
      init=tv.tv_sec + tv.tv_usec*0.000001;
    
      for(i=0;i<num_iter;++i)
    
        {
    
          gettimeofday( &tv,&tz);
    
          start=tv.tv_sec + tv.tv_usec*0.000001;
    
         
    
          // Now sleep
    
          usleep(delay);
    
          gettimeofday( &tv,&tz);
    
          stop=tv.tv_sec + tv.tv_usec*0.000001;
    
               
    
          printf("Iteration %d..slept for %lf usec\n",i+1,(stop-start)*1000000);
    
        }
    
     
    
    printf("Total time taken : actual %lf  theory(excl. runtime): %d,   usec \n",(stop-init)*1000000,num_iter*delay);
    
    return 0;
    
    }
    


Comments

  • Registered Users, Registered Users 2 Posts: 3,875 ✭✭✭ShoulderChip


    sorry, no.


  • Subscribers Posts: 4,076 ✭✭✭IRLConor


    #include <stdlib.h>
    
    ?

    When you get errors like that, look up the manpage for the missing functions (e.g. "man atoi") and it will usually tell you what you need to include at the top.


  • Registered Users, Registered Users 2 Posts: 357 ✭✭apoch632


    Cheers man. I'd a feeling it was something silly like that i left out.


Advertisement