Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > assignment makes pointer from integer without a cast...help please.

Reply
Thread Tools

assignment makes pointer from integer without a cast...help please.

 
 
Rocke Robertson
Guest
Posts: n/a
 
      09-30-2003
Take it easy on me. I dont do a lot of programmng, only on a as needed
basis. For the life of me, I cant get rid of the error. Its the usual
casting problem. But I have cast the return type properly havent I ?

Here is the error....

larg.c: In function `page_n_loggit':
larg.c:29: warning: assignment makes pointer from integer without a cast

The error is refering to the popen() function. Below is all the code.

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

page_n_loggit(char * host, char * str) {

static FILE *logfp;
static FILE *ptr;
char fn[] = " ";
char PatrolAlert[] = "Patrol Alert 1.0";
char PatrolLDAPErr[] = "CUSTOM_LDAP.gtis0.ldapStatus";
char alarm[] = "ALARM";
char *cmd;

/* Prime rand() */

srand(getpid());
sprintf(fn,"patfile.%d",rand());

if ((logfp = fopen(fn, "w")) == NULL)
perror("fopen failed");

fprintf(logfp,
"%s\n%s\n%s\n%s\n%s\n",PatrolAlert,PatrolLDAPErr,h ost,str,alarm);
fflush(logfp);
fclose(logfp);

sprintf(cmd, "/gtis/bin/ftp_file %s /alarm", fn);

if (( ptr = popen(cmd, "w")) == NULL)
perror("popen");

exit(0);

}



 
Reply With Quote
 
 
 
 
Mark A. Odell
Guest
Posts: n/a
 
      09-30-2003
Rocke Robertson <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> The error is refering to the popen() function. Below is all the code.
>
> #include <stdio.h>
> #include <stdlib.h>


[snip]

> if (( ptr = popen(cmd, "w")) == NULL)


Since popen(), which is not part of C, is not prototyped, C considers it
to return type 'int'. Since you are assigning the int return of this
popen() function to a pointer you get the error as expected. I suggest you
include the non-standard header file that has the prototype for popen()
and re-compile. If popen() is normally prototyped in stdio.h for your
system, be sure your compiler is pulling the correct version of stdio.h.

--
- Mark ->
--
 
Reply With Quote
 
 
 
 
Rocke Robertson
Guest
Posts: n/a
 
      09-30-2003


"Mark A. Odell" wrote:

> Rocke Robertson <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
> > The error is refering to the popen() function. Below is all the code.
> >
> > #include <stdio.h>
> > #include <stdlib.h>

>
> [snip]
>
> > if (( ptr = popen(cmd, "w")) == NULL)

>
> Since popen(), which is not part of C, is not prototyped, C considers it
> to return type 'int'. Since you are assigning the int return of this
> popen() function to a pointer you get the error as expected. I suggest you
> include the non-standard header file that has the prototype for popen()
> and re-compile. If popen() is normally prototyped in stdio.h for your
> system, be sure your compiler is pulling the correct version of stdio.h.
>
> --
> - Mark ->
> --


Shoot, maybe I should have posted to comp.unix.programmers because this is for
a unix system. In response to your comments, popen() is prototyped in stdio.h,
and I have included that header. There is only one version of stdio.h on the
system.

# ls /usr/include/stdio*
/usr/include/stdio.h /usr/include/stdio_impl.h
/usr/include/stdio_ext.h /usr/include/stdio_tag.h

Thanks


 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      09-30-2003
"Mark A. Odell" wrote:
>
> Rocke Robertson <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
> > The error is refering to the popen() function. Below is all the code.
> >
> > #include <stdio.h>
> > #include <stdlib.h>

>
> [snip]
>
> > if (( ptr = popen(cmd, "w")) == NULL)

>
> Since popen(), which is not part of C, is not prototyped, C considers it
> to return type 'int'. Since you are assigning the int return of this
> popen() function to a pointer you get the error as expected. I suggest you
> include the non-standard header file that has the prototype for popen()
> and re-compile. If popen() is normally prototyped in stdio.h for your
> system, be sure your compiler is pulling the correct version of stdio.h.


In addition to the immediate error that Mark explained,
there are other problems with the code. For example,

char fn[] = " ";
...
sprintf(fn,"patfile.%d",rand());

is a recipe for disaster, and the other sprintf() call has
the problem described in Question 7.1 of the comp.lang.c
Frequently Asked Questions (FAQ) list

http://www.eskimo.com/~scs/C-faq/top.html

There's also the little matter of detecting fopen() and
popen() failures (good) but doing nothing about them (bad).

--
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      09-30-2003
Rocke Robertson wrote:
>
> "Mark A. Odell" wrote:
>
> > Rocke Robertson <(E-Mail Removed)> wrote in
> > news:(E-Mail Removed):
> >
> > > The error is refering to the popen() function. Below is all the code.
> > >
> > > #include <stdio.h>
> > > #include <stdlib.h>

> >
> > [snip]
> >
> > > if (( ptr = popen(cmd, "w")) == NULL)

> >
> > Since popen(), which is not part of C, is not prototyped, C considers it
> > to return type 'int'. Since you are assigning the int return of this
> > popen() function to a pointer you get the error as expected. I suggest you
> > include the non-standard header file that has the prototype for popen()
> > and re-compile. If popen() is normally prototyped in stdio.h for your
> > system, be sure your compiler is pulling the correct version of stdio.h.
> >
> > --
> > - Mark ->
> > --

>
> Shoot, maybe I should have posted to comp.unix.programmers because this is for
> a unix system. In response to your comments, popen() is prototyped in stdio.h,
> and I have included that header. There is only one version of stdio.h on the
> system.


You will probably find that the popen() declaration is
guarded by #if or #ifdef preprocessor tests, and is not
"effectively" included if you're running the compiler in
a Standard-conforming mode. (In fact, if #include <stdio.h>
introduces a declaration of popen(), the implementation is
non-conforming; `popen' is in the space of names guaranteed
to be available to the programmer.)

You probably need to invoke the compiler in an "extended"
non-conforming mode, perhaps with something like `-DPOSIX_SOURCE'
on the command line. See your implementation's documentation
for details on how to get access to non-conforming language
extensions.

--
(E-Mail Removed)
 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      09-30-2003
Rocke Robertson <(E-Mail Removed)> wrote:

> "Mark A. Odell" wrote:
>
> > Since popen(), which is not part of C, is not prototyped, C considers it
> > to return type 'int'.

>
> Shoot, maybe I should have posted to comp.unix.programmers because this is for
> a unix system. In response to your comments, popen() is prototyped in stdio.h,


Not in ISO C, it isn't.

Maybe the problem is that you're not only accidentally posting to an ISO
C newsgroup, but also accidentally compiling this as ISO C code. A
properly written header would then #ifdef out all non-ISO POSIX bits.
Try to find out what you need to #define to make your compiler assume
POSIX code (IIRC it's POSIX_SOURCE or similar).

Richard
 
Reply With Quote
 
Rocke Robertson
Guest
Posts: n/a
 
      09-30-2003


Eric Sosman wrote:

> You will probably find that the popen() declaration is
> guarded by #if or #ifdef preprocessor tests, and is not
> "effectively" included if you're running the compiler in
> a Standard-conforming mode. (In fact, if #include <stdio.h>
> introduces a declaration of popen(), the implementation is
> non-conforming; `popen' is in the space of names guaranteed
> to be available to the programmer.)
>
> You probably need to invoke the compiler in an "extended"
> non-conforming mode, perhaps with something like `-DPOSIX_SOURCE'
> on the command line. See your implementation's documentation
> for details on how to get access to non-conforming language
> extensions.
>
> --
> (E-Mail Removed)


For what its worth, Im trying to build this on a Solaris 7 SPARC system using the
all too ubiquitous gcc 2.9.5.

 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      09-30-2003
Rocke Robertson <(E-Mail Removed)> scribbled the following:
> Eric Sosman wrote:
>> You will probably find that the popen() declaration is
>> guarded by #if or #ifdef preprocessor tests, and is not
>> "effectively" included if you're running the compiler in
>> a Standard-conforming mode. (In fact, if #include <stdio.h>
>> introduces a declaration of popen(), the implementation is
>> non-conforming; `popen' is in the space of names guaranteed
>> to be available to the programmer.)
>>
>> You probably need to invoke the compiler in an "extended"
>> non-conforming mode, perhaps with something like `-DPOSIX_SOURCE'
>> on the command line. See your implementation's documentation
>> for details on how to get access to non-conforming language
>> extensions.


> For what its worth, Im trying to build this on a Solaris 7 SPARC system using the
> all too ubiquitous gcc 2.9.5.


Rule of thumb in comp.lang.c: If what OS, or what compiler, you are
using matters even the slightest bit, you're off-topic. So far I've
found this rule of thumb very useful.

--
/-- Joona Palaste ((E-Mail Removed)) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Stronger, no. More seductive, cunning, crunchier the Dark Side is."
- Mika P. Nieminen
 
Reply With Quote
 
Micah Cowan
Guest
Posts: n/a
 
      10-01-2003
Rocke Robertson <(E-Mail Removed)> writes:

> Take it easy on me. I dont do a lot of programmng, only on a as needed
> basis. For the life of me, I cant get rid of the error. Its the usual
> casting problem. But I have cast the return type properly havent I ?
>
> Here is the error....
>
> larg.c: In function `page_n_loggit':
> larg.c:29: warning: assignment makes pointer from integer without a cast
>
> The error is refering to the popen() function. Below is all the code.
>
> #include <stdio.h>
> #include <stdlib.h>
>
> page_n_loggit(char * host, char * str) {
>
> static FILE *logfp;
> static FILE *ptr;
> char fn[] = " ";
> char PatrolAlert[] = "Patrol Alert 1.0";
> char PatrolLDAPErr[] = "CUSTOM_LDAP.gtis0.ldapStatus";
> char alarm[] = "ALARM";
> char *cmd;
>
> /* Prime rand() */
>
> srand(getpid());
> sprintf(fn,"patfile.%d",rand());
>
> if ((logfp = fopen(fn, "w")) == NULL)
> perror("fopen failed");
>
> fprintf(logfp,
> "%s\n%s\n%s\n%s\n%s\n",PatrolAlert,PatrolLDAPErr,h ost,str,alarm);
> fflush(logfp);
> fclose(logfp);
>
> sprintf(cmd, "/gtis/bin/ftp_file %s /alarm", fn);
>
> if (( ptr = popen(cmd, "w")) == NULL)
> perror("popen");
>
> exit(0);
>
> }


A lot of your code above, including popen(), is not standard C
and is thus offtopic here; it would be on-topic I believe at
news:comp.unix.programmer

I suspect that a declaration is not in scope for popen(), so its
return type is defaulting to int (BTW, the missing return type in
your function prototype for page_n_loggit() is illegal now in
C99). Make sure that you are invoking your compiler in such a way
to include extensions, or (better yet) #define the appropriate
macro before your #includes so that POSIX extensions are
included. For example:

#define _POSIX_C_SOURCE 199506L

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

HTH,
Micah
 
Reply With Quote
 
Rocke Robertson
Guest
Posts: n/a
 
      10-01-2003


Eric Sosman wrote:

> You will probably find that the popen() declaration is
> guarded by #if or #ifdef preprocessor tests, and is not
> "effectively" included if you're running the compiler in
> a Standard-conforming mode. (In fact, if #include <stdio.h>
> introduces a declaration of popen(), the implementation is
> non-conforming; `popen' is in the space of names guaranteed
> to be available to the programmer.)
>
> You probably need to invoke the compiler in an "extended"
> non-conforming mode, perhaps with something like `-DPOSIX_SOURCE'
> on the command line. See your implementation's documentation
> for details on how to get access to non-conforming language
> extensions.
>
> --
> (E-Mail Removed)


I added a #define _POSIX_SOURCE before I declare my headers and this fixed my
problems.
Sorry I was off topic, nevertheless, thanks for all your input.

~rocker

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
assignment makes pointer from integer without a cast Zach C Programming 3 05-05-2009 09:42 PM
Help: "Assignment makes integer from pointer without a cast" Juggernaut C Programming 10 04-09-2005 08:00 AM
warning: passing arg 1 of `atoi' makes pointer from integer without a cast francescomoi@europe.com C Programming 2 04-01-2005 05:30 PM
warning: assignment makes integer from pointer without a cast Dawn Minnis C Programming 4 02-20-2005 07:02 PM
fmemopen: assignment makes pointer from integer without a cast Markus Dehmann C Programming 14 06-28-2004 01:12 PM



Advertisments