suspicious limited range of data type

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

suspicious limited range of data type

Thomas Steinbach
Hello,

I have an another problem, which I dont't understand.

I have a function which check some things to ensure that
a date ist really a date, but get the following errors:

main.c: In function `EvaluateDate':
main.c:343: warning: comparison is always true due to limited range of data
type

The Code-Segment which is involved is:

100 WORD wCentYear = 0;
101 WORD wCent = 0;
102 WORD wYear = 0;

[...]

337 else {
338     if( !((70<=wYear)&&(wYear<=99)) ) {
339         _tcscpy(szCent, _T("19"));
340         wCentYear = 1900 + (WORD)_ttoi(szYear);
341         wCent = 19;
342     }
343     if( !((0<=wYear)&&(wYear<=69)) ) {
344         _tcscpy(szCent, _T("20"));
345         wCentYear = 2000 + (WORD)_ttoi(szYear);
346         wCent = 20;
347     }
348     _tcscpy(szCentYear, szCent);
349     _tcscat(szCentYear, szYear);
350     if( !((1970<=wCentYear)&&(wCentYear<=2069)) ) {
351         return FALSE;
352     }
353 }


Don't understand that, because WORD should be large enough to store
any value with two values, shoulnd't it?

Thomas



------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: suspicious limited range of data type

Роман Донченко
Thomas Steinbach <[hidden email]> писал  
в своём письме Mon, 07 Dec 2009 01:31:49 +0300:

> Hello,
>
> I have an another problem, which I dont't understand.
>
> I have a function which check some things to ensure that
> a date ist really a date, but get the following errors:
>
> main.c: In function `EvaluateDate':
> main.c:343: warning: comparison is always true due to limited range of  
> data
> type
>
> The Code-Segment which is involved is:
>
> 100 WORD wCentYear = 0;
> 101 WORD wCent = 0;
> 102 WORD wYear = 0;
>
> [...]
>
> 337 else {
> 338     if( !((70<=wYear)&&(wYear<=99)) ) {
> 339         _tcscpy(szCent, _T("19"));
> 340         wCentYear = 1900 + (WORD)_ttoi(szYear);
> 341         wCent = 19;
> 342     }
> 343     if( !((0<=wYear)&&(wYear<=69)) ) {
> 344         _tcscpy(szCent, _T("20"));
> 345         wCentYear = 2000 + (WORD)_ttoi(szYear);
> 346         wCent = 20;
> 347     }
> 348     _tcscpy(szCentYear, szCent);
> 349     _tcscat(szCentYear, szYear);
> 350     if( !((1970<=wCentYear)&&(wCentYear<=2069)) ) {
> 351         return FALSE;
> 352     }
> 353 }
>
>
> Don't understand that, because WORD should be large enough to store
> any value with two values, shoulnd't it?
>

0<=wYear is always true, because WORD is unsigned.

Roman.


------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: suspicious limited range of data type

Thomas Steinbach
Hello,

>> main.c:343: warning: comparison is always true due to limited range of
>> data type

> 0<=wYear is always true, because WORD is unsigned.

ok, now I understand. ;-)
The reason is that it is unsigned and that warning should come up
every _unsigned_ "int" var. Thank you...

btw: With the mingw 4.4.x compiler I didn't get that error.

Thomas


------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users