Мой код следующий:
#include <iostream>
#include <sys/time.h>
using namespace std;
int main(int argc, char** argv) {
if(argv[0])
argc++;
struct timeval m_timeEnd, m_timeCreate, m_timeStart;
long mtime, alltime, seconds, useconds;
gettimeofday(&m_timeStart,NULL);
sleep(3);
gettimeofday(&m_timeCreate,NULL);
sleep(1);
gettimeofday(&m_timeEnd, NULL);
seconds = m_timeEnd.tv_sec - m_timeStart.tv_sec;
useconds = m_timeEnd.tv_usec - m_timeStart.tv_usec;
mtime = (long) (((seconds) * 1000 + useconds/1000.0) + 0.5);
seconds = useconds = 0;
seconds = m_timeEnd.tv_sec - m_timeCreate.tv_sec;
useconds = m_timeEnd.tv_usec - m_timeCreate.tv_usec;
alltime = (long) (((seconds) * 1000 + useconds/1000.0) + 0.5);
printf("IN=%ld ALL=%ld milsec.\n", mtime, alltime);
}
Я компилирую с
g ++ -W -Wall -Wno-unknown-pragmas -Wpointer-arith -Wcast-align
-Wcast-qual -Wsign-сравнить -Wconversion -O -fno-строгого псевдонима
и у меня есть несколько предупреждений, которые мне нужно устранить. Как?
a1.cpp:21: warning: conversion to 'double' from 'long int' may alter its value
a1.cpp:21: warning: conversion to 'double' from 'long int' may alter its value
a1.cpp:25: warning: conversion to 'double' from 'long int' may alter its value
a1.cpp:25: warning: conversion to 'double' from 'long int' may alter its value