Trying to find out time_t size and i have 4 bytes?

Posted on 2011-10-28
Last Modified: 2012-05-12
Hi there;

I am trying to find a time_t struct size and what I have got is 4 bytes. Isn't it 8 bytes?

Here you go, for the code;

Kind regards.
# include <stdio.h>
# include <iostream>
# include <time.h>
using namespace std;
size_t getPtrSize( char *ptr )
	return sizeof( ptr );

int main()
	time_t lt;

	lt = time(NULL);
	cout << "Date: " << ctime(&lt) << endl;

	cout << "\nThe length of " << ctime(&lt) << " is: "
		 << sizeof ctime(&lt)
		 << "\nThe size of the pointer is "
		 << getPtrSize( ctime(&lt) ) << endl;

	return 0;

Open in new window

Question by:jazzIIIlove
    LVL 31

    Accepted Solution

    Try using

    cout << sizeof(time_t);

    Address of pointers is always the same irrespective of the data type
    LVL 12

    Author Comment

    Ok, working.

    But why 4, not 8 with my code? I mean, could you explain that, before I conclude this question?

    LVL 31

    Assisted Solution

    Sizes are dependent upon your architecture.

    Sizes of integers vary.  Sizes of pointer even vary.  If you run your code on anther machine, you may see a different value.

    See this  
    and search for "size in memory"
    LVL 39

    Assisted Solution

    Just to clarify what farzanj has already said...

    >> But why 4, not 8 with my code?
    Because on your architecture a pointer is 4 bytes (32 bits).

    >> Isn't it 8 bytes?
    No. From the C standard: The range and precision of times representable in clock_t and time_t are implementation-defined.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
    Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
    The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now