Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8167409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:11:02+00:00 2026-06-06T20:11:02+00:00

#include <ctime> #include <cstdio> #include <sys/time.h> #include <iostream> using namespace std; int main() {

  • 0
#include <ctime>
#include <cstdio>
#include <sys/time.h>
#include <iostream>
using namespace std;

int main() {
    struct timeval tv;
    gettimeofday(&tv, 0);
    unsigned long long int var=tv.tv_sec*1000L+tv.tv_usec/1000L;
    cout<<sizeof(var)<<endl;
    cout<<var<<endl;
    printf("%u%-15u\n", (unsigned int)(var/1000000000), (unsigned int)(var%1000000000));
    return 0;
}

This thing prints

8
1341143123970
1341143123970      

on my 64 bit machine, but

8
1113191712
1113191712      

on my 32 bit server. The second result is evidently clamped to a 32 bit number, but unsigned long long int is 8 bytes on both architectures. Where is the clamping happening then, and why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:11:04+00:00Added an answer on June 6, 2026 at 8:11 pm

    It is because the width of long is not the same on your 32-bit and 64-bit machines. The type of tv_sec is an arithmetic type, usually1) long.

    You can ensure the multiplication is done with a 64-bit type by using 1000ULL instead of 1000L:

    unsigned long long int var=tv.tv_sec*1000ULL+tv.tv_usec/1000ULL;
    


    1) On glibc for example, it is long. "In the GNU C library, time_t is equivalent to long int" http://www.gnu.org/software/libc/manual/html_node/Simple-Calendar-Time.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <iostream> using namespace std; int main() { int a, b, c, max; cout<<a=;
#include <iostream> #include <string.h> using namespace std; int main() { int e=0; int b=0;
#include <ctime> #include <iostream> #include <cstring> int main() { struct tm tm ; //memset(&tm,
#include <iostream> #include <string> using namespace std; string crash() { } int noCrash() {
#include <iostream> #include <cassert> #include <vector> #include <ctime> #include <cstdlib> #include <Windows.h> using namespace
#include <iostream> #include <tuple> int main(){ auto bt=std::make_tuple(std::tuple<>(),std::tuple<std::tuple<>>()); //Line 1 auto bt2=std::make_tuple(std::tuple<>(),std::tuple<>()); //Line 2
I'm using the following short program to test std::clock() : #include <ctime> #include <iostream>
I have a question about the following code : #include <iostream> #include <ctime> int
Here is my program time_play.c : #include <stdlib.h> #include <stdio.h> #include <time.h> int main
I'm testing the following code: #include <iostream> #include <vector> #include <algorithm> #include <ctime> int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.