time.h

How can adding a header increase portability? (sys/time.h)

北战南征 提交于 2019-12-20 03:14:49
问题 I just noticed this line in the getrusage man page: Including <sys/time.h> is not required these days, but increases portability. (Indeed, struct timeval is defined in <sys/time.h> ) What? Since struct rusage contains struct timeval as a member, surely sys/resource.h must include sys/time.h or the type would be incomplete and unusable? How could this comment ever have made sense? How could it ever have not been necessary? How could portability have ever been helped? 回答1: In general, it was

Constants not loaded by compiler

强颜欢笑 提交于 2019-12-18 23:14:06
问题 I started studying POSIX timers, so I started also doing some exercises, but I immediately had some problems with the compiler. When compiling this code, I get some strange messages about macros like CLOCK_MONOTONIC. Those are defined in various libraries like time.h etc. but the compiler gives me errors as if they are not defined. It is strange because I am using a Fedora 16, and some of my friends with Ubuntu get less compiler errors than I :-O I am compiling with gcc -O0 -g3 -Wall -c

Constants not loaded by compiler

心不动则不痛 提交于 2019-12-18 23:13:07
问题 I started studying POSIX timers, so I started also doing some exercises, but I immediately had some problems with the compiler. When compiling this code, I get some strange messages about macros like CLOCK_MONOTONIC. Those are defined in various libraries like time.h etc. but the compiler gives me errors as if they are not defined. It is strange because I am using a Fedora 16, and some of my friends with Ubuntu get less compiler errors than I :-O I am compiling with gcc -O0 -g3 -Wall -c

C++ error: undefined reference to 'clock_gettime' and 'clock_settime'

被刻印的时光 ゝ 提交于 2019-12-17 10:15:25
问题 I am pretty new to Ubuntu, but I can't seem to get this to work. It works fine on my school computers and I don't know what I am not doing. I have checked usr/include and time.h is there just fine. Here is the code: #include <iostream> #include <time.h> using namespace std; int main() { timespec time1, time2; int temp; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1); //do stuff here clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2); return 0; } I am using CodeBlocks as my IDE to build and run

C++ Undefined reference to function implemented and templated in code

送分小仙女□ 提交于 2019-12-14 03:12:16
问题 First of all, the function which I am trying to call isn't in an external library. It is part of the following (I am getting back into C++, so I thought I would start by writing my own cron daemon implementation) Here is my code: #include <iostream> #include <fstream> #include <cstdlib> #include <time.h> using namespace std; //Global Variables: //local time in the form of a tm struct struct tm sysclocktime; /* * tm_sec int seconds after the minute 0-60* * tm_min int minutes after the hour 0

C++ clock stays zero

孤街浪徒 提交于 2019-12-13 16:12:05
问题 Im trying get the elapsed time of my program. Actually i thought I should use yclock() from time.h . But it stays zero in all phases of the program although I'm adding 10^5 numbers(there must be some CPU time consumed). I already searched this problem and it seems like, people running Linux are having this issue only. I'm running Ubuntu 12.04LTS. I'm going to compare AVX and SSE instructions, so using time_t is not really an option. Any hints? Here is the code: //Dimension of Arrays unsigned

timestamp in c with milliseconds precision

橙三吉。 提交于 2019-12-12 12:40:08
问题 I'm relatively new to C programming and I'm working on a project which needs to be very time accurate; therefore I tried to write something to create a timestamp with milliseconds precision. It seems to work but my question is whether this way is the right way, or is there a much easier way? Here is my code: #include<stdio.h> #include<time.h> void wait(int milliseconds) { clock_t start = clock(); while(1) if(clock() - start >= milliseconds) break; } int main() { time_t now; clock_t milli; int

difference between two date in C

一个人想着一个人 提交于 2019-12-12 10:44:02
问题 I am trying to get the difference between two date by using below C code. but code always giving difference 0. Help me to where i am making mistake. I am using gcc compiler under linux. #include <stdio.h> #include <time.h> int main () { struct tm start_date; struct tm end_date; time_t start_time, end_time; double seconds; start_date.tm_hour = 0; start_date.tm_min = 0; start_date.tm_sec = 0; start_date.tm_mon = 10; start_date.tm_mday = 15; start_date.tm_year = 2013; end_date.tm_hour = 0; end

Getting the Timing of a Specific Part of Code in a Loop in C

会有一股神秘感。 提交于 2019-12-12 10:25:37
问题 Description of Problem Below I have a program that is performing two simple addition and multiplication operations. I am then storing the sum of these two simple operations in two respective variables called total1 and total2. In terms of computation total2 will take more time to be fully executed. The way I implemented the code, I am currently timing the entire simulation of both mathematical operations. Question Is it possible to time solely the end result of total1 and total 2 separately?

How to set (or correct for) timezone & DST in c (time.h functions) and DOS

强颜欢笑 提交于 2019-12-12 02:28:43
问题 I have a computer running DOS (freeDos 1.1) and plain C (compiled with Borland 5.0) with time.h . When I set the computer time using BIOS or the DATE and TIME DOS commands, there is no information about time zone. I set the time to my current time 10:25 AM. My C program does this... char timeString[80]; time_t timeT = time(NULL); strftime(timeString, sizeof(timeString), "%a %Y-%m-%d %H:%M:%S %Z", localtime(&timeT)); printf("%s\n", timeString); when I run the code I get the correct current