R
Rahul
Hi,
I have a little program as follows :
=================== STARTS HERE ================
#include <stdio.h>
void f (unsigned long);
int main()
{
short s=0x7FFF; /* == 32767 */
/* == 0x8000 == 32768 (in unsigned) == -32768 (in
signed) */
s++;
/* passing signed short to f(), which expects unsigned long */
f(s);
return (0);
}
void f(unsigned long l)
{
/* note the huge value passed here */
printf ("value is unsigned long = (%lu), hexadecimal =
(0x%lX)\n",
l, l);
}
=================== ENDS HERE ================
(FYI : I am using Solaris Workshop 6.2 on Solaris 8).
Running the above program (compiled with -xarch=v9 option -- for
64-bit), gives me following result (which I guess, expected) :
--------
value is unsigned long = (18446744073709518848), hexadecimal =
(0xFFFFFFFFFFFF8000)
--------
If I run lint to catch such mismatch datatype, I cann't see any
complains from lint :-( ...
lint -errchk=%all a.c (note, %all includes sizematch see
http://docs.sun.com/db/doc/805-4952/6j4mdcehi?a=view), gives me
following output :
-------
function returns value which is always ignored
printf
declared global, could be static
f a.c(19)
-------
My question is : Is there any way that I can catch such wrong
mismatchs in datatypes (-errchk=sizematch does catch if I pass
unsigned to signed, but not the other way)?
Thanks a lot!
RMD.
I have a little program as follows :
=================== STARTS HERE ================
#include <stdio.h>
void f (unsigned long);
int main()
{
short s=0x7FFF; /* == 32767 */
/* == 0x8000 == 32768 (in unsigned) == -32768 (in
signed) */
s++;
/* passing signed short to f(), which expects unsigned long */
f(s);
return (0);
}
void f(unsigned long l)
{
/* note the huge value passed here */
printf ("value is unsigned long = (%lu), hexadecimal =
(0x%lX)\n",
l, l);
}
=================== ENDS HERE ================
(FYI : I am using Solaris Workshop 6.2 on Solaris 8).
Running the above program (compiled with -xarch=v9 option -- for
64-bit), gives me following result (which I guess, expected) :
--------
value is unsigned long = (18446744073709518848), hexadecimal =
(0xFFFFFFFFFFFF8000)
--------
If I run lint to catch such mismatch datatype, I cann't see any
complains from lint :-( ...
lint -errchk=%all a.c (note, %all includes sizematch see
http://docs.sun.com/db/doc/805-4952/6j4mdcehi?a=view), gives me
following output :
-------
function returns value which is always ignored
printf
declared global, could be static
f a.c(19)
-------
My question is : Is there any way that I can catch such wrong
mismatchs in datatypes (-errchk=sizematch does catch if I pass
unsigned to signed, but not the other way)?
Thanks a lot!
RMD.