warning: integer overflow in expression

I have the following expression:

#define GB                      (1024 * 1024 * 1024)
#define TB                      (1024 * GB)
#define MAX_SIZE                (3 * TB)

off_t                            current_size;

And then the expression...

if (current_size > MAX_SIZE) 
{
   //do something
}

I have used large file support in my program. Compiled using -D_FILE_OFFSET_BITS=64 flag.

So, with large file support, off_t grows from 32 to 64 bits.

But how do I compare something which is off_t with a 64 bit number ?? How do I use a 64 bit number in an expression ??

#define MAX_SIZE (3ul * TB) will also fail because ul is still 32 bits.

please help me.. I am looking for a portable solution.. thanks :)))

Alas you can't have a once size fits all if the maximum datatype on some platforms is 32 bits.

Next, some compilers support a "long long" which is 64 bit and works in a 32 bit environment, however this is compiler and platform dependant.

WIN32 has a __int64 datatype for this purpose.

The only platforms you are guarranteed a simple portable solution are 64 bit platforms of the LP64 type where a long is 64 bits.

You could however do the following, define a constant which is actually a global variable, eg

extern long long myMaxSize;

#define MAX_SIZE     myMaxSize

and in the source where you define it, put in

long long myMaxSize=(3*1024*1024*1024*1024);

or

unsigned long long myMaxSize=0x30000000000;