Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compilers LCC > Re: what does t...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 986 of 1062
Post > Topic >>

Re: what does this warning mean ?

by John J. Smith <jjs@[EMAIL PROTECTED] > Sep 28, 2007 at 03:49 PM

U wrote:
[followup set to c.l.c]

> [crossposted to comp.compilers.lcc]
> 
> In comp.lang.c, Heinrich Pumpernickel wrote:
> 
>> what does this warning mean ?
>> 
>> 
>> #include <stdio.h>
>> 
>> int main()
>> {
>>         long l = 100;
>> 
>>         printf("l is %li\n", l * 10L);
>> 
>>         return 0;
>> }
>> 
>> 
>> when i compile this program with lcc-win32 it prints
>> 
>> lcc -A -ansic -O long.c -o long.obj
>> Warning c:\tmp\long.c: 4  old-style function definition for 'main'
>> Warning c:\tmp\long.c: 4  missing prototype for 'main'
>> Warning c:\tmp\long.c: 4  'int main()' is a non-ANSI definition
>> Warning c:\tmp\long.c: 7  printf argument mismatch for format i.
>> Expected long int got int
>> 0 errors, 4 warnings
> 
> [snip]
> 
> <OT group="c.l.c">
> 
> One thing I observed a long time ago is that lcc-win32 sometimes
> produces warnings for operations on signed types but not for the
> same operations on unsigned types.
> 
>   *long -> *int                    ==> diagnostic
>   *unsigned long -> *unsigned int  ==> no diagnostic
> 
> The same seems to be true for printf() arguments as well,
> 
>   long l; unsigned long ul;
>   printf("%li\n", l * 10);         ==> diagnostic
>   printf("%lu\n", lu * 10);        ==> no diagnostic
> 
> 
> /*** begin lcctest.c ***/
> 
> #include <stdio.h>
> 
> volatile void *foo;
> 
> int main(void)
> {
>   long l = 100;
>   unsigned long ul = 100;
> 
>   int *pi = &l;                 /* line 12: produces diagnostic */
>   unsigned int *pui = &ul;      /* line 13: no diagnostic       */
> 
>   /* prevent prev. two statements from being optimized away     */
>   foo = pi; foo = pui;
> 
>   printf("  l * 10: %li\n", l * 10);
>   printf(" ul * 10: %lu\n", ul * 10);
> 
>   return 0;
> }
> 
> /*** end lcctest.c ***/
> 
> $ wine lcc -ansic -A -O lcctest.c
> Warning z:\src\clc\lcctest.c: 12  assignment of pointer to long int to
> pointer to int
> Warning z:\src\clc\lcctest.c: 18  printf argument mismatch for format i.
> Expected long int got int
> 0 errors, 2 warnings
> 
> </OT>
> 

Um... wouldn't line 13 be a constraint violation and every
conforming compiler is *required* to issue a diagnostic even
when not at the highest warning level? (even warning about 
line 12 is not issued without "-A".)

I have extended your test with some suspicious pointer 
assignments involving 'char' and no diagnostic is issued for
those either, even at the highest warning level.

Gcc warns about lines 12, 13, 14, and 15.

Which of those are really required by the standard?


Modified test and compiler output follows.

/*** begin lcctest.c (modified by jss) ***/

#include <stdio.h>

volatile void *foo;

int main(void)
{
    long l = 100;
    unsigned long ul = 100;
    char c = 1;

    int *pi = &l;               /* line 12 */
    unsigned int *pui = &ul;    /* line 13 */
    signed char *psc = &c;      /* line 14 */
    unsigned char *puc = &c;    /* line 15 */

    /* prevent prev. two statements from being optimized away */
    foo = pi; foo = pui; foo = psc; foo = puc;

    printf("  l * 10: %li\n", l * 10);
    printf(" ul * 10: %lu\n", ul * 10);

    return 0;
}

/*** end lcctest.c ***/

lcc output:

$ wine lcc -ansic -A -O lcctest.c
Warning z:\home\jss\src\clc\lcctest.c: 14  assignment of pointer to long
int
to pointer to int
Warning z:\home\jss\src\clc\lcctest.c: 22  printf argument mismatch for
format i. Expected long int got int
0 errors, 2 warnings

gcc output:

$ gcc-4.2 -Wall -W -ansi -pedantic -O2 -c lcctest.c
lcctest.c: In function 'main':
lcctest.c:13: warning: initialization from incompatible pointer type
lcctest.c:14: warning: initialization from incompatible pointer type
lcctest.c:15: warning: pointer targets in initialization differ in
signedness
lcctest.c:16: warning: pointer targets in initialization differ in
signedness


-- 
John J. Smith
(Just Curious)
 




 1 Posts in Topic:
Re: what does this warning mean ?
John J. Smith <jjs@[EM  2007-09-28 15:49:05 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 20:06:27 CDT 2008.