Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 7072

Chrono library compilation issue with g++ and clang++

$
0
0

I am trying to work with epoch in chrono library, but I am getting different results while running with g++ and clang++ can anyone help me?

#include <chrono>#include <iostream>#include <cstring>using std::string;uint64_t timeToEpoch(uint64_t day, uint64_t month, uint64_t year, uint64_t hour, uint64_t min, uint64_t second, uint64_t microsecond){    string timeT = std::to_string(day) +"-" + std::to_string(month) +"-" + std::to_string(year) +" " + std::to_string(hour) +":" + std::to_string(min) +":" + std::to_string(second);    char *time_T = new char[(timeT.length() + 1)];    strcpy(time_T, timeT.c_str());    struct tm tm;    strptime(time_T, "%d-%m-%Y %H:%M:%S", &tm);    uint64_t t = mktime(&tm);    t = (t * 1000000) + microsecond;    return t; }string epochToTime(uint64_t epochTime){    string timeT;    uint64_t microsecond = epochTime % 1000000;    time_t epochTimeInSec = (epochTime - microsecond) / 1000000;    char time_T[21];    strftime(time_T, 20, "%d-%m-%Y %H:%M:%S", localtime(&epochTimeInSec));    timeT = time_T;    timeT = timeT +":" + std::to_string(microsecond);    return timeT; }int main(){    std::cout << "Year changed 2004 to 2005\n";    uint64_t time_info_1 = timeToEpoch(31, 12, 2004, 23, 59, 59, 999999);    uint64_t time_info_2 = timeToEpoch(1, 1, 2005, 0, 0, 0, 9);    std::cout << "First timestamp in epoch :" << time_info_1 << "\n";    std::cout << "Second timestamp in epoch: " << time_info_2 << "\n\n";    std::cout << "Difference between both timestamp in microsecond: " << (time_info_2 - time_info_1) << "\n\n";    std::cout << "First timestamp converted from epoch: " << epochToTime(time_info_1) << "\n";    std::cout << "Second timestamp converted from epoch: " << epochToTime(time_info_2) << "\n";    return 0;}

This is my c++ code which is working properly with g++

This is my c++ code which is working properly with g++

But it's not working with clang:

But not working with clang


Viewing all articles
Browse latest Browse all 7072

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>