Warning missing?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sergio.borghese@gmail.com

    #1

    Warning missing?

    Hello,

    Why this code compile without any warning?
    I compile it on gcc 3.3.4 with the following command:

    gcc -Wall -pedantic -ansi test.c

    #include <stdlib.h>
    #include <stdio.h>

    int pippo(inx)
    {
    return inx/2;
    }

    int main(void)
    {
    int i = 6;
    char c = 12;

    printf("%d", pippo(i));
    printf("%d", pippo(c));
    return 0;
    }

    Thank to all.

    Sergio

  • Default User

    #2
    Re: Warning missing?


    sergio.borgh... @gmail.com wrote:[color=blue]
    > Hello,
    >
    > Why this code compile without any warning?[/color]


    What warning did you expect?




    Brian

    Comment

    • Keith Thompson

      #3
      Re: Warning missing?

      sergio.borghese @gmail.com writes:[color=blue]
      > Why this code compile without any warning?
      > I compile it on gcc 3.3.4 with the following command:
      >
      > gcc -Wall -pedantic -ansi test.c
      >
      > #include <stdlib.h>
      > #include <stdio.h>
      >
      > int pippo(inx)
      > {
      > return inx/2;
      > }
      >
      > int main(void)
      > {
      > int i = 6;
      > char c = 12;
      >
      > printf("%d", pippo(i));
      > printf("%d", pippo(c));
      > return 0;
      > }[/color]

      What warning were you expecting?

      <OT>"-W -Wall" enables more warnings than "-W" alone.</OT>

      --
      Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
      San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
      We must do something. This is something. Therefore, we must do this.

      Comment

      • Martin Ambuhl

        #4
        Re: Warning missing?

        sergio.borghese @gmail.com wrote:[color=blue]
        > Hello,
        >
        > Why this code compile without any warning?[/color]

        I don't know why your version of gcc compiles without warning. _My_
        copy gives this warning:
        a.c:5: warning: type of "inx" defaults to "int"

        Comment

        • sergio.borghese@gmail.com

          #5
          Re: Warning missing?


          Martin Ambuhl wrote:[color=blue]
          > sergio.borghese @gmail.com wrote:[color=green]
          > > Hello,
          > >
          > > Why this code compile without any warning?[/color]
          >
          > I don't know why your version of gcc compiles without warning. _My_
          > copy gives this warning:
          > a.c:5: warning: type of "inx" defaults to "int"[/color]

          I would expect a warning like that: in my sample code the argument type
          is missing in the function.

          Which gcc version you have?

          Thanks,

          Sergio

          Comment

          • Martin Ambuhl

            #6
            Re: Warning missing?

            sergio.borghese @gmail.com wrote:[color=blue]
            > Martin Ambuhl wrote:
            >[color=green]
            >>sergio.borghe se@gmail.com wrote:
            >>[color=darkred]
            >>>Hello,
            >>>
            >>>Why this code compile without any warning?[/color]
            >>
            >>I don't know why your version of gcc compiles without warning. _My_
            >>copy gives this warning:
            >>a.c:5: warning: type of "inx" defaults to "int"[/color]
            >
            >
            > I would expect a warning like that: in my sample code the argument type
            > is missing in the function.
            >
            > Which gcc version you have?[/color]

            This belong in a gcc or gnu newsgroup. My version is 3.4.3. Please
            direct any further questions to an appropriate newsgroup.

            Comment

            • Ben Pfaff

              #7
              Re: Warning missing?

              sergio.borghese @gmail.com writes:
              [color=blue]
              > I would expect a warning like that: in my sample code the argument type
              > is missing in the function.[/color]

              Your code looked like this:
              int foo(bar)
              {
              ...
              }
              This is a valid non-prototype style function definition. It
              could be written more explicitly like this:
              int foo(bar)
              int bar;
              {
              ...
              }
              If you want a warning about the absence of a prototype, GCC has
              an option for that.
              --
              int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
              \n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
              );while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
              );}return 0;}

              Comment

              • Emmanuel Delahaye

                #8
                Re: Warning missing?

                sergio.borghese @gmail.com wrote on 08/04/05 :[color=blue]
                > Hello,
                >
                > Why this code compile without any warning?
                > I compile it on gcc 3.3.4 with the following command:
                >
                > gcc -Wall -pedantic -ansi test.c[/color]

                Well, I must have a different tuning :

                main.c:9: warning: function declaration isn't a prototype
                main.c: In function `pippo':
                main.c:9: warning: type of `inx' defaults to `int'

                gcc.exe -c main.c -o dexe/main.o -W -Wall -O2 -Wshadow -Wpointer-arith
                -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion
                -Waggregate-return -Wstrict-prototypes -Wredundant-decls
                -Wnested-externs -Winline
                [color=blue]
                > #include <stdlib.h>
                > #include <stdio.h>
                >
                > int pippo(inx)
                > {
                > return inx/2;
                > }
                >
                > int main(void)
                > {
                > int i = 6;
                > char c = 12;
                >
                > printf("%d", pippo(i));
                > printf("%d", pippo(c));
                > return 0;
                > }[/color]

                --
                Emmanuel
                The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
                The C-library: http://www.dinkumware.com/refxc.html

                I once asked an expert COBOL programmer, how to
                declare local variables in COBOL, the reply was:
                "what is a local variable?"

                Comment

                Working...