regcmp warning: improper pointer/integer combination: op "="

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jose_luis_fdez_diaz_news@yahoo.es

    #1

    regcmp warning: improper pointer/integer combination: op "="


    Hi,

    If I don't include <libgen.h> I get then warnig below in regcmp call:

    warning: improper pointer/integer combination: op "="

    but if I include it the warning is not shown, but them program compiles
    fine.

    What is the warning shown ?

    Thanks,
    Jose Luis.

  • jacob navia

    #2
    Re: regcmp warning: improper pointer/integer combination: op &quot;=&quot ;

    jose_luis_fdez_ diaz_news@yahoo .es wrote:[color=blue]
    > Hi,
    >
    > If I don't include <libgen.h> I get then warnig below in regcmp call:
    >
    > warning: improper pointer/integer combination: op "="
    >
    > but if I include it the warning is not shown, but them program compiles
    > fine.
    >
    > What is the warning shown ?
    >
    > Thanks,
    > Jose Luis.
    >[/color]

    In C all functions return an int if the prototype is not known to the
    compiler.

    If you have a function that returns a pointer like:

    char *fn(void);

    you can do this in your code without problems:

    char *a = fn();

    Now, if the compiler doesn't see the prototype, the fn function is
    assumed to return an integer, that gets assigned to char char pointer
    a. Assignment of an integer to a pointer is not a very good idea,
    even if "it works", so the compiler warns you about it.

    Solution:

    DO INCLUDE all necessary header files when compiling.

    jacob

    Comment

    • CBFalconer

      #3
      Re: regcmp warning: improper pointer/integer combination: op &quot;=&quot ;

      jose_luis_fdez_ diaz_news@yahoo .es wrote:[color=blue]
      >
      > If I don't include <libgen.h> I get then warnig below in regcmp call:
      >
      > warning: improper pointer/integer combination: op "="
      >
      > but if I include it the warning is not shown, but them program
      > compiles fine.
      >
      > What is the warning shown ?[/color]

      There is no such standard include file in C, nor is there any such
      routine as regcmp. You will have to show the code for these to
      receive any reasonable answer.

      --
      "If you want to post a followup via groups.google.c om, don't use
      the broken "Reply" link at the bottom of the article. Click on
      "show options" at the top of the article, then click on the
      "Reply" at the bottom of the article headers." - Keith Thompson

      Comment

      • Flash Gordon

        #4
        Re: regcmp warning: improper pointer/integer combination: op &quot;=&quot ;

        jose_luis_fdez_ diaz_news@yahoo .es wrote:[color=blue]
        > Hi,
        >
        > If I don't include <libgen.h> I get then warnig below in regcmp call:
        >
        > warning: improper pointer/integer combination: op "="
        >
        > but if I include it the warning is not shown, but them program compiles
        > fine.
        >
        > What is the warning shown ?[/color]

        Well, without the source code one can only guess. However, I would
        assume regcmp (which is not part of standard C) returns some kind of
        pointer, and that you are assigning it to an appropriate pointer
        variable. I further assume that the non-standard header libgen.h
        provides a prototype for the non-standard regcmp function.

        In C, if there is no declaration of a function in scope when it is used
        it is assumed to return an int. The compiler is required to issue a
        diagnostic (a warning in this case) when you assign an int directly to a
        pointer, which is what is occurring without the prototype that libgen.h
        probably provides.

        So include the headers (I assume libgen.h) that the manuals (or man
        pages) for your system tell you to include for the non-standard
        functions you are using.

        Of course, if you had asked about this on a group dedicated to your
        system then the people answering would know if libgen.h was the correct
        header to include. Here we deal with standard C not extensions provided
        by specific implementations .
        --
        Flash Gordon
        Living in interesting times.
        Although my email address says spam, it is real and I read it.

        Comment

        • Mark McIntyre

          #5
          Re: regcmp warning: improper pointer/integer combination: op &quot;=&quot ;

          On Tue, 08 Mar 2005 14:31:21 GMT, in comp.lang.c , CBFalconer
          <cbfalconer@yah oo.com> wrote:
          [color=blue]
          >jose_luis_fdez _diaz_news@yaho o.es wrote:[color=green]
          >>
          >> If I don't include <libgen.h> I get then warnig below in regcmp call:
          >>
          >> warning: improper pointer/integer combination: op "="
          >>
          >> but if I include it the warning is not shown, but them program
          >> compiles fine.
          >>
          >> What is the warning shown ?[/color]
          >
          >There is no such standard include file in C, nor is there any such
          >routine as regcmp. You will have to show the code for these to
          >receive any reasonable answer.[/color]

          No he doesn't - its perfectly possible to explain this without knowing
          anything outside Standard C. Indeed jacob navia's answer was it.

          CBF this is about the nth time you've unjustly posted in this vein. Is it
          worth stepping back from the keyboard for a couple of days?

          --
          Mark McIntyre
          CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
          CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

          ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
          http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
          ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

          Comment

          • CBFalconer

            #6
            Re: regcmp warning: improper pointer/integer combination: op &quot;=&quot ;

            Mark McIntyre wrote:[color=blue]
            > <cbfalconer@yah oo.com> wrote:[color=green]
            >> jose_luis_fdez_ diaz_news@yahoo .es wrote:[color=darkred]
            >>>
            >>> If I don't include <libgen.h> I get then warnig below in regcmp call:
            >>>
            >>> warning: improper pointer/integer combination: op "="
            >>>
            >>> but if I include it the warning is not shown, but them program
            >>> compiles fine.
            >>>
            >>> What is the warning shown ?[/color]
            >>
            >> There is no such standard include file in C, nor is there any such
            >> routine as regcmp. You will have to show the code for these to
            >> receive any reasonable answer.[/color]
            >
            > No he doesn't - its perfectly possible to explain this without
            > knowing anything outside Standard C. Indeed jacob navia's answer
            > was it.
            >
            > CBF this is about the nth time you've unjustly posted in this
            > vein. Is it worth stepping back from the keyboard for a couple
            > of days?[/color]

            Color me stoopid, but I don't see any such diagnosis. It is just
            one of many possibilities, and nobody can tell without seeing the
            source.

            --
            Chuck F (cbfalconer@yah oo.com) (cbfalconer@wor ldnet.att.net)
            Available for consulting/temporary embedded and systems.
            <http://cbfalconer.home .att.net> USE worldnet address!


            Comment

            • DHOLLINGSWORTH2

              #7
              Re: regcmp warning: improper pointer/integer combination: op &quot;=&quot ;

              Actually someone familliar with the error codes returned durring a build,
              and for a particular platform, they can answer this question without seeing
              any code.

              and in the example

              char *pc = fn();

              if you know it should fit then:

              char *pc = (char * ) fn();

              makes it fit.

              "Flash Gordon" <spam@flash-gordon.me.uk> wrote in message
              news:l8r0g2xgdc .ln2@brenda.fla sh-gordon.me.uk...[color=blue]
              > jose_luis_fdez_ diaz_news@yahoo .es wrote:[color=green]
              >> Hi,
              >>
              >> If I don't include <libgen.h> I get then warnig below in regcmp call:
              >>
              >> warning: improper pointer/integer combination: op "="
              >>
              >> but if I include it the warning is not shown, but them program compiles
              >> fine.
              >>
              >> What is the warning shown ?[/color]
              >
              > Well, without the source code one can only guess. However, I would assume
              > regcmp (which is not part of standard C) returns some kind of pointer, and
              > that you are assigning it to an appropriate pointer variable. I further
              > assume that the non-standard header libgen.h provides a prototype for the
              > non-standard regcmp function.
              >
              > In C, if there is no declaration of a function in scope when it is used it
              > is assumed to return an int. The compiler is required to issue a
              > diagnostic (a warning in this case) when you assign an int directly to a
              > pointer, which is what is occurring without the prototype that libgen.h
              > probably provides.
              >
              > So include the headers (I assume libgen.h) that the manuals (or man pages)
              > for your system tell you to include for the non-standard functions you are
              > using.
              >
              > Of course, if you had asked about this on a group dedicated to your system
              > then the people answering would know if libgen.h was the correct header to
              > include. Here we deal with standard C not extensions provided by specific
              > implementations .
              > --
              > Flash Gordon
              > Living in interesting times.
              > Although my email address says spam, it is real and I read it.[/color]


              Comment

              • Jens.Toerring@physik.fu-berlin.de

                #8
                Re: regcmp warning: improper pointer/integer combination: op &quot;=&quot ;

                DHOLLINGSWORTH2 <DHOLLINGSWORTH 2@cox.net> wrote:[color=blue]
                > "Flash Gordon" <spam@flash-gordon.me.uk> wrote in message
                > news:l8r0g2xgdc .ln2@brenda.fla sh-gordon.me.uk...[color=green]
                >> jose_luis_fdez_ diaz_news@yahoo .es wrote:[color=darkred]
                >>> Hi,
                >>>
                >>> If I don't include <libgen.h> I get then warnig below in regcmp call:
                >>>
                >>> warning: improper pointer/integer combination: op "="
                >>>
                >>> but if I include it the warning is not shown, but them program compiles
                >>> fine.
                >>>
                >>> What is the warning shown ?[/color]
                >>
                >> Well, without the source code one can only guess. However, I would assume
                >> regcmp (which is not part of standard C) returns some kind of pointer, and
                >> that you are assigning it to an appropriate pointer variable. I further
                >> assume that the non-standard header libgen.h provides a prototype for the
                >> non-standard regcmp function.
                >>
                >> In C, if there is no declaration of a function in scope when it is used it
                >> is assumed to return an int. The compiler is required to issue a
                >> diagnostic (a warning in this case) when you assign an int directly to a
                >> pointer, which is what is occurring without the prototype that libgen.h
                >> probably provides.
                >>
                >> So include the headers (I assume libgen.h) that the manuals (or man pages)
                >> for your system tell you to include for the non-standard functions you are
                >> using.
                >>
                >> Of course, if you had asked about this on a group dedicated to your system
                >> then the people answering would know if libgen.h was the correct header to
                >> include. Here we deal with standard C not extensions provided by specific
                >> implementations .[/color][/color]
                [color=blue]
                > Actually someone familliar with the error codes returned durring a build,
                > and for a particular platform, they can answer this question without seeing
                > any code.[/color]
                [color=blue]
                > and in the example[/color]
                [color=blue]
                > char *pc = fn();[/color]
                [color=blue]
                > if you know it should fit then:[/color]
                [color=blue]
                > char *pc = (char * ) fn();[/color]
                [color=blue]
                > makes it fit.[/color]

                Looks like clc acquired another troll, top-posting, spewing misin-
                formation dangerous for unsuspecting newbies and all...

                To the OP: Never, ever mindlessly use a cast just to get rid of a
                compiler warning. The warning indicates that the compiler found
                something that looks fishy. But by casting you tell the compiler
                "Shut up, I know what I am doing, get out of my way". Unless you
                really mean it don't do that but try to understand why you get the
                warning (and you posted here because you didn't, did you) and what
                is the best way to avoid it. Use casts only after you understood
                all implications and are sure it's the only and right thing to do.

                And here, as "Flesh Gordon" explained perfectly well, a cast is
                obviously not necessary (actually, it would be a bad thing to use)
                since you only get it when you don't include the header file that
                declares the (return type of the) function you're calling.

                Regards, Jens
                --
                \ Jens Thoms Toerring ___ Jens.Toerring@p hysik.fu-berlin.de
                \______________ ____________ http://www.toerring.de

                Comment

                • DHOLLINGSWORTH2

                  #9
                  Re: regcmp warning: improper pointer/integer combination: op &quot;=&quot ;

                  I'm glad to see that you DO agree with me on one or two points.

                  It's too bad you like to hear it from your own mouth.

                  As far as missinformation goes I've been writting programs since 1986.

                  And although you may not be familiar with a product, doesn't mean every body
                  else is just as ignorant.

                  [color=blue]
                  > To the OP: Never, ever mindlessly use a cast just to get rid of a
                  > compiler warning. The warning indicates that the compiler found
                  > something that looks fishy. But by casting you tell the compiler[/color]

                  Actually I agreed with the man that he doesn't need to see the code. And
                  aparently you, who hasn't seen the code, agrees with both of us.
                  [color=blue]
                  >But by casting you tell the compiler
                  > "Shut up, I know what I am doing, get out of my way". Unless you
                  > really mean it don't do that but try to understand why you get the[/color]

                  Is this not what I just said?

                  [color=blue]
                  >spewing misin-
                  > formation dangerous for unsuspecting newbies and all...
                  >[/color]
                  You have confirmed every bit of information I spewed.
                  Thank you.
                  [color=blue]
                  > Looks like clc acquired another troll, top-posting,[/color]

                  Stick it in your ass!


                  Comment

                  • Flash Gordon

                    #10
                    Re: regcmp warning: improper pointer/integer combination: op &quot;=&quot ;

                    DHOLLINGSWORTH2 wrote:[color=blue]
                    > I'm glad to see that you DO agree with me on one or two points.
                    >
                    > It's too bad you like to hear it from your own mouth.
                    >
                    > As far as missinformation goes I've been writting programs since 1986.[/color]

                    That does not mean that you actually know what you are talking about or
                    that you are not giving misinformation.
                    [color=blue]
                    > And although you may not be familiar with a product, doesn't mean every body
                    > else is just as ignorant.[/color]

                    This group does not deal with implementation specifics. There are plenty
                    of groups that do.

                    I happen to believe the CBF was over zealous since I believe a good
                    indication could be obtained from the diagnostic without knowing the
                    specific implementation. However, note that I still considered it worth
                    redirecting the OP because the function in question *is* on-standard so
                    it is only the diagnostic that gives us a clue as to what the problem was.
                    [color=blue][color=green]
                    >>To the OP: Never, ever mindlessly use a cast just to get rid of a
                    >>compiler warning. The warning indicates that the compiler found
                    >>something that looks fishy. But by casting you tell the compiler[/color]
                    >
                    > Actually I agreed with the man that he doesn't need to see the code. And
                    > aparently you, who hasn't seen the code, agrees with both of us.[/color]

                    I was able to take a good guess and based on that give a standard C
                    answer about the probable problem. However, there are likely to be other
                    problems that the OP needs to address that we can't do here.
                    [color=blue][color=green]
                    >>But by casting you tell the compiler
                    >>"Shut up, I know what I am doing, get out of my way". Unless you
                    >>really mean it don't do that but try to understand why you get the[/color]
                    >
                    > Is this not what I just said?[/color]

                    When a function actually returns a pointer, casting to get rid of the
                    warning due to not having the declaration in scope is NEVER the right
                    thing to do. As I almost said to the OP (but thought it too much
                    information) you actually invoke undefined behaviour and one REAL way
                    this fails on some implementations is the address being returned in
                    register A0 but the compiler reading from D0 (because it thinks an
                    integer is returned) and so storing garbage in the pointer variable
                    whilst ignoring the real pointer value. So whether you know "it should
                    fit" is not the question, the question is whether the compiler knows the
                    real return type. Also, I cannot think of any instances where it is
                    appropriate to have a function actually return an int and the program
                    then cast that to a pointer type and store it in a pointer.
                    [color=blue][color=green]
                    >>spewing misin-
                    >>formation dangerous for unsuspecting newbies and all...[/color]
                    >
                    > You have confirmed every bit of information I spewed.
                    > Thank you.[/color]

                    No, you suggested that casting might be an appropriate solution. It is
                    definitely NOT the correct solution.

                    <OT>
                    regcmp declared in libgen.h *does* return a pointer to char, so casting
                    would definitely invoke undefined behaviour and almost certainly cause
                    the program to fail on some real *nix implementations , it almost
                    certainly being a *nix program.
                    </OT>
                    [color=blue][color=green]
                    >>Looks like clc acquired another troll, top-posting,[/color]
                    >
                    > Stick it in your ass![/color]

                    The *only* reason I'm not plonking you is that any further
                    misinformation you spew needs to be corrected to try to prevent people
                    who do not know any better from believing you.
                    --
                    Flash Gordon
                    Living in interesting times.
                    Although my email address says spam, it is real and I read it.

                    Comment

                    • Flash Gordon

                      #11
                      Re: regcmp warning: improper pointer/integer combination: op &quot;=&quot ;

                      Jens.Toerring@p hysik.fu-berlin.de wrote:[color=blue]
                      > DHOLLINGSWORTH2 <DHOLLINGSWORTH 2@cox.net> wrote:
                      >[color=green]
                      >>"Flash Gordon" <spam@flash-gordon.me.uk> wrote in message
                      >>news:l8r0g2xg dc.ln2@brenda.f lash-gordon.me.uk...[/color][/color]

                      <snip>
                      [color=blue]
                      > And here, as "Flesh Gordon" explained perfectly well, a cast is[/color]

                      Actually, it is Flash Gordon. Flesh Gordon is my dirty minded twin :-)
                      --
                      Flash Gordon
                      Living in interesting times.
                      Although my email address says spam, it is real and I read it.

                      Comment

                      • Jens.Toerring@physik.fu-berlin.de

                        #12
                        Re: regcmp warning: improper pointer/integer combination: op &quot;=&quot ;

                        Flash Gordon <spam@flash-gordon.me.uk> wrote:[color=blue]
                        > Jens.Toerring@p hysik.fu-berlin.de wrote:[color=green]
                        >> DHOLLINGSWORTH2 <DHOLLINGSWORTH 2@cox.net> wrote:
                        >>[color=darkred]
                        >>>"Flash Gordon" <spam@flash-gordon.me.uk> wrote in message
                        >>>news:l8r0g2x gdc.ln2@brenda. flash-gordon.me.uk...[/color][/color][/color]
                        [color=blue]
                        > <snip>[/color]
                        [color=blue][color=green]
                        >> And here, as "Flesh Gordon" explained perfectly well, a cast is[/color][/color]
                        [color=blue]
                        > Actually, it is Flash Gordon. Flesh Gordon is my dirty minded twin :-)[/color]

                        Oh, sorry. Didn't mean to do that (but I plead innocence, I had to
                        google to find out what's the difference between you two;-)

                        Regards, Jens
                        --
                        \ Jens Thoms Toerring ___ Jens.Toerring@p hysik.fu-berlin.de
                        \______________ ____________ http://www.toerring.de

                        Comment

                        • Richard Bos

                          #13
                          Re: regcmp warning: improper pointer/integer combination: op &quot;=&quot ;

                          "DHOLLINGSWORTH 2" <DHOLLINGSWORTH 2@cox.net> wrote:
                          [color=blue]
                          > "Flash Gordon" <spam@flash-gordon.me.uk> wrote in message
                          > news:l8r0g2xgdc .ln2@brenda.fla sh-gordon.me.uk...[color=green]
                          > > jose_luis_fdez_ diaz_news@yahoo .es wrote:[color=darkred]
                          > >> If I don't include <libgen.h> I get then warnig below in regcmp call:
                          > >>
                          > >> warning: improper pointer/integer combination: op "="
                          > >>
                          > >> but if I include it the warning is not shown, but them program compiles
                          > >> fine.
                          > >>
                          > >> What is the warning shown ?[/color]
                          > >
                          > > Well, without the source code one can only guess. However, I would assume
                          > > regcmp (which is not part of standard C) returns some kind of pointer, and
                          > > that you are assigning it to an appropriate pointer variable.[/color][/color]
                          [color=blue]
                          > Actually someone familliar with the error codes returned durring a build,
                          > and for a particular platform, they can answer this question without seeing
                          > any code.[/color]

                          Which is exactly what Mr. Gordon did, and correctly, which is more than
                          can be said for your answer.
                          [color=blue]
                          > and in the example
                          >
                          > char *pc = fn();
                          >
                          > if you know it should fit then:
                          >
                          > char *pc = (char * ) fn();
                          >
                          > makes it fit.[/color]

                          No, it doesn't. If there is no declaration for fn() in scope, the
                          implementation assumes it returns int. Casting this int to char * may,
                          but need not, result in the char * that was originally returned from
                          fn().
                          If, for example, the implementation optimises function calls by
                          returning scalars in registers rather than on the stack, and by using
                          separate address and integer registers where available, your cast is
                          going to result in a lot of random garbage being returned.

                          Just provide a proper declaration for all your functions, if at all
                          possible by #including the appropriate headers, and you'll never have to
                          worry about such bogus casts again.

                          Richard

                          Comment

                          • Flash Gordon

                            #14
                            Re: regcmp warning: improper pointer/integer combination: op &quot;=&quot ;

                            Jens.Toerring@p hysik.fu-berlin.de wrote:[color=blue]
                            > Flash Gordon <spam@flash-gordon.me.uk> wrote:
                            >[color=green]
                            >>Jens.Toerring @physik.fu-berlin.de wrote:
                            >>[color=darkred]
                            >>>DHOLLINGSWOR TH2 <DHOLLINGSWORTH 2@cox.net> wrote:
                            >>>
                            >>>>"Flash Gordon" <spam@flash-gordon.me.uk> wrote in message
                            >>>>news:l8r0g2 xgdc.ln2@brenda .flash-gordon.me.uk...[/color][/color]
                            >[color=green]
                            >><snip>[/color]
                            >[color=green][color=darkred]
                            >>>And here, as "Flesh Gordon" explained perfectly well, a cast is[/color][/color]
                            >[color=green]
                            >>Actually, it is Flash Gordon. Flesh Gordon is my dirty minded twin :-)[/color]
                            >
                            > Oh, sorry. Didn't mean to do that (but I plead innocence, I had to
                            > google to find out what's the difference between you two;-)[/color]

                            Just as long as you did not do the googling from work. Your employer
                            might not understand ;-)
                            --
                            Flash Gordon
                            Living in interesting times.
                            Although my email address says spam, it is real and I read it.

                            Comment

                            • DHOLLINGSWORTH2

                              #15
                              Re: regcmp warning: improper pointer/integer combination: op &quot;=&quot ;

                              And I could pretend to be an ass and say that none of youtr examples work
                              becuase they have no main proc in them.

                              And I may be wrong, but Type casting is a no no, then why is it in the
                              STANDARD?

                              Bullocks


                              Comment

                              Working...