enable 64bit long type for gcc

hey, I believe I once saw a post in this forum, about enable an GCC option to enable long types. I simply cannot find it any more. Can anybody give me a hint? I am on 32bit Ubuntu, and I would like my int be really long. Also I need malloc() take long int argument too.

I found it is necessary to have really long types to use GNU C library time.h functions since the seconds since epoch is too long.

Do you mean enable the long long datatype? gcc supports that by default, when configure runs during gcc install it turns off support for long long if the system does not support it.

Or do you want a 64 bit executable?

gcc does have a -mlong64 option, but only for MIPS processors. long long datatypes should be 64-bit on most 32-bit processors, while long should already be 64-bit on 64-bit processors.

hey, jim, thanks for reply. I am not sure 64bit executable is what I want since I am using a 32 bit machine :(.

I experienced a lots of error while using gnu c library time.h functions, where time_t type variable is used a lot. Wierd enough, say in my main() I get a time_t tim=1230768000 returned by localtime(). And I pass it to a function A(time_t tim). Inside the A() I see tim become negative value!!!

Hopefully I expressed the problem clearly :confused:!

Thanks for your reply.

time_t ought to be time_t, you shouldn't need special datatypes other than time_t itself to deal with it. That means you shouldn't try to feed it through a long or an int either, always use the time_t datatype. The negative numbers are an artifact from converting a large unsigned number into a signed one.

I ran this in a 32 bit executable under ubuntu:

#include <sys/types.h>
#include <stdio.h>

void foo(time_t t)
{
	printf("%u\n", t); 
	printf("%d\n", t);
}

int main()
{
	time_t tim=1230768000;
	foo(tim);
	return 0;
}

This is what I got:

/home/jmcnama> a.out
1230768000
1230768000

You have a coding problem not a datatype problem. Can you post the shortest possible chunk of code that shows your problem?

Hey, Jim, thanks for the tip, it is really encouraging! You are right, it is not a problem of size of the storage. It is my program error. My unfinished makefile didn't automatically delete the old library I generated before linking, and leads to prototype mismatch from signed type to unsigned type. And I am totally lost while playing with long int, long long int and other datatypes while the old library file is there! Thanks!