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

Jens.Toerring_at_physik.fu-berlin.de
Date: 03/09/05


Date: 9 Mar 2005 09:24:14 GMT

DHOLLINGSWORTH2 <DHOLLINGSWORTH2@cox.net> wrote:
> "Flash Gordon" <spam@flash-gordon.me.uk> wrote in message
> news:l8r0g2xgdc.ln2@brenda.flash-gordon.me.uk...
>> jose_luis_fdez_diaz_news@yahoo.es wrote:
>>> 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 ?
>>
>> 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.

> 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.

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@physik.fu-berlin.de
   \__________________________  http://www.toerring.de


Relevant Pages

  • Re: function declaration overloading in C
    ... compiler that will end up as open-source sometime in the future. ... I think it would be nice if you went against the norm and produced a compiler that by default conformed to the C standard with a high level of additional warnings and the user had to explicitly switch on extensions and turn the warning level down if required. ... It would still be behaving entirely within what the standard allowed if it failed to compile the above program, or if the compiled program printed, "your mother is a bloated warthog" or reformatted your hard disk. ...
    (comp.lang.c)
  • Re: Comparing two numbers
    ... a C compiler is needed to tranlate C source code. ... C does define a keyword to facilitate ... > not at all standard, not part of the C language. ...
    (comp.lang.c)
  • Re: Supressing Unused Parameter Warnings
    ... Because there is no standard diagnostic about unused parameters. ... "unused parameter" warning is purely a "quality of implementation" ... as is any way your compiler might provide to shut it off. ... On GCC, you can also write ...
    (comp.lang.c)
  • Re: Internal Compiler Error // Stupid Standards?
    ... > just curious as to whether this is Microsoft's problem in their compiler ... > getting a warning, stating that a non-standard extention was being used. ... > try to make my programs as standard as possible. ... > the reference, it is exactly the same thing. ...
    (comp.lang.cpp)
  • Re: FD_SET compiler warning, why that particular warniing?
    ... it issued this warning for that line number: ... though why a compiler would choose to emit that particular message. ... FD_SET is not part of standard C, but it's defined as a function-like ... that's why gcc gets confused.) ...
    (comp.lang.c)