warning: integer overflow in expression


 
Thread Tools Search this Thread
Top Forums Programming warning: integer overflow in expression
# 1  
Old 06-26-2007
warning: integer overflow in expression

I have the following expression:

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

off_t                            current_size;

And then the expression...

Code:
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 Smilie))
# 2  
Old 06-26-2007
Quote:
Originally Posted by tantric
I am looking for a portable solution.. thanks Smilie))
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

Code:
extern long long myMaxSize;

#define MAX_SIZE     myMaxSize

and in the source where you define it, put in

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

or

Code:
unsigned long long myMaxSize=0x30000000000;

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Integer expression expected

Hi, I am getting the below error while comparing the month of a file to current month. I am using ls -lrth to get the month of that file and while using the if else condition i am getting the below error.. a1=`ls -lrth abc.txt | awk '{print substr($6,1,3)}'` This gives me the month from... (1 Reply)
Discussion started by: jaituteja
1 Replies

2. Shell Programming and Scripting

Integer expression expected

I need some help with this if but then it says line 11: I don't know what I'm doing wrong (1 Reply)
Discussion started by: margg
1 Replies

3. Shell Programming and Scripting

Integer expression expected

Hi, I have placed the script and running successfully on AIX However in Linux it throws integer expression expected Could some one please help me to fix this MaxThreshold4alert=`echo "$MaxCapacitycnt*(80/100)" |bc -l` echo $MaxThreshold4alert Error: 40.00000000000000000000: integer... (2 Replies)
Discussion started by: ajothi
2 Replies

4. Shell Programming and Scripting

Integer expression expected

Newb here echo "$yesterdaysclose" echo "$close" if ; then echo "stocks moving up" elif ; then echo "stock is moving down" else echo "no change" fi seems to evaluate the floating decimal correctly however returns ./shellscript1.sh: line 17: [: : integer expression expected... (3 Replies)
Discussion started by: harte
3 Replies

5. UNIX for Dummies Questions & Answers

Integer Expression Expected!?!?

Ok, so I am beggining a script to factor the time difference from when a user logs on to current time but before I can even get too far I am getting the INTEGER EXPRESSION EXPECTED error. Can someone tell me what I am doing wrong? lhour=$(who | grep "$1" | cut -c30,31); lmin=$(who | grep "$1"... (1 Reply)
Discussion started by: losingit
1 Replies

6. Shell Programming and Scripting

Integer expression expected: with regular expression

CA_RELEASE has a value of 6. I need to check if that this is a numeric value. if not error. source $CA_VERSION_DATA if * ] then echo "CA_RELESE $CA_RELEASE is invalid" exit -1 fi + source /etc/ncgl/ca_version_data ++ CA_PRODUCT_ID=samxts ++ CA_RELEASE=6 ++ CA_WEEK_NO=7 ++... (3 Replies)
Discussion started by: ketkee1985
3 Replies

7. Shell Programming and Scripting

:integer expression expected

Hi, echo $i until || do read NUM if && ; then printf "$FBOLD\nInvalid number, please enter valid backup number: $FREG" fi done Getting below error : ./import_location.sh: line 234: [: : integer expression expected ./import_location.sh: line 234: [: :... (5 Replies)
Discussion started by: milink
5 Replies

8. Shell Programming and Scripting

KSH arithmatic Integer overflow

Guys, I have two big numbers to multiply. In doing do I am getting integer overflow. I managed to multiply number but this number is useless as KSh does not recognise it as a valid number. Here is what I am doing $ expr 999999999999 \* 100 276447132 I got the right value by doing... (2 Replies)
Discussion started by: vikas_sri
2 Replies
Login or Register to Ask a Question