Thread: error: invalid use of undefined type ‘struct tms’

  1. #1
    programmer hacker DevZero's Avatar
    Join Date
    Jul 2017
    Posts
    42

    error: invalid use of undefined type ‘struct tms’

    This:
    Code:
    #include <stdio.h>
    #include <sys/time.h>
    #include <time.h>
    
    struct tms tmsBegin,tmsEnd;
    void time_start() { times(&tmsBegin); }
    long time_stop()
    { times(&tmsEnd);
      return ((tmsEnd.tms_utime-tmsBegin.tms_utime)+
              (tmsEnd.tms_stime-tmsBegin.tms_stime))*1000/CLK_TCK;
    }
    
    int main()
    {
    	time_start();
    	for(int t=0; t<1000000; t++)
    	    printf("Test 1: %d\n", t);
    	printf("Result: %ld\n", time_stop());
    }
    I took this code from the Internet, here's the log after trying to copy:
    Code:
    test.c: In function ‘time_start’:
    test.c:6:1: warning: implicit declaration of function ‘times’ [-Wimplicit-function-declaration]
     void time_start() { times(&tmsBegin); }
     ^
    test.c: In function ‘time_stop’:
    test.c:9:3: error: invalid use of undefined type ‘struct tms’
       return ((tmsEnd.tms_utime-tmsBegin.tms_utime)+
       ^
    test.c:9:3: error: invalid use of undefined type ‘struct tms’
    test.c:10:11: error: invalid use of undefined type ‘struct tms’
               (tmsEnd.tms_stime-tmsBegin.tms_stime))*1000/CLK_TCK;
               ^
    test.c:10:11: error: invalid use of undefined type ‘struct tms’

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 08-03-2015, 01:30 PM
  2. Replies: 3
    Last Post: 04-07-2014, 05:38 PM
  3. Error from "invalid use of undefined type `struct '"
    By HashTagTeddy in forum C Programming
    Replies: 8
    Last Post: 05-10-2013, 05:05 PM
  4. invalid use of incomplete type 'struct a'
    By ajoqiqu in forum C++ Programming
    Replies: 19
    Last Post: 05-16-2010, 11:59 AM
  5. Replies: 0
    Last Post: 11-29-2002, 10:24 PM

Tags for this Thread