🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.programmer
3 messages
3 total messages Started by Zhenbin (Kevin) Xu Mon, 16 Mar 1998 00:00
Why do I get warnings using popen in g++??? Help needed!
#3431
Author: Zhenbin (Kevin) Xu
Date: Mon, 16 Mar 1998 00:00
80 lines
3080 bytes
>Sun OS 5.5
>g++  version unknown, probably very old (1993???)
>
>First of all, my program complied without any warning in my Linux box.
>However, not in this Sun box...
>
>I got the following warnings:
>    msgqueue.cpp: In function `int DoServer()':
>    msgqueue.cpp:190: warning: implicit declaration of function `int
>popen(...)'
>    msgqueue.cpp:190: warning: initialization to `FILE *' from `int' lacks
a
>cast
>    msgqueue.cpp:192: warning: implicit declaration of function `int
>pclose(...)'
>
>Here is the context:
>  if( strlen(msgpackage.mtext) > 0 )
>  {
>    #ifdef _MYDEBUG
>       cout << "Server: rcv: " << msgpackage.mtext << endl;
>    #endif
>       char cmdLine[MSGBUFSIZE+24];
>       sprintf(cmdLine,"%s%s",cmdPing,msgpackage.mtext);
>+     FILE* fp=popen(cmdLine,"r");
>+     int iStatus=0;
>+     switch( pclose(fp) ) // pclose returns the termination status of
>cmdLine
>       {
>       case 0:
>        iStatus = HOST_ALIVE;
>        break;
>       default:
>        iStatus = HOST_DEAD;
>       }
>       sprintf( msgpackage.mtext +
>strlen(msgpackage.mtext),"\t%s",STR_HOST_STATUS[iStatus] );
>       msgpackage.mtype = SERVER_DATA;
>       msgsnd( msg_id, (MSGStruct)&msgpackage, MSGBUFSIZE, 0);
>      }
>
>It seems very clear that the "popen" and "pclose" are not declared in the
>header file. However, they suppose to be declared in stdio.h and here is my
>includes:
>    #include <sys/types.h>
>    #include <sys/ipc.h>
>    #include <sys/msg.h>
>    #include <limits.h>
>    #include <unistd.h>
>    #include <syslog.h>
>    #include <errno.h>
>    #include <string.h>
>    #include <stdio.h>
>    #include <stdlib.h>
>    #include <fstream.h>
>    #include <iostream.h>
>
>I suspect that this is because that I primarily use C++ functions and there
>are some preprocess symbols need to be declared/cleared.  If it is the
case,
>how can I use popen in my C++ program in SUN OS with a probably obsoleted
>g++ version???
>
>Once again, there is no any syntax and logical error when I run this
program
>on my Linux machine. However, I need it to be able to run on that stupid
Sun
>box as well - and worst of all, I am primary a Windows programmer.
>
>Any information will be very much appreciated! Please also reply to my
>account at kevin@blueshoe.com .
>
>Thanks in advance,
>Kevin
>
>
>
>
>
Re: Why do I get warnings using popen in g++??? Help needed!
#3430
Author: Zhenbin (Kevin) Xu
Date: Mon, 16 Mar 1998 00:00
94 lines
3593 bytes
I found out that I have to define __EXTENSIONS_  (or something like
_POSIX_...) before any include headers. The key point (in my undrestanding)
is that SunOS distinguishes between ANSI C and POSIX. popen and pclose
happen to not belong ANSI C standard library. And thus the warning.

Regards,
Kevin

Zhenbin (Kevin) Xu wrote in message
<6ejp15$5ja@bgtnsc03.worldnet.att.net>...
>>Sun OS 5.5
>>g++  version unknown, probably very old (1993???)
>>
>>First of all, my program complied without any warning in my Linux box.
>>However, not in this Sun box...
>>
>>I got the following warnings:
>>    msgqueue.cpp: In function `int DoServer()':
>>    msgqueue.cpp:190: warning: implicit declaration of function `int
>>popen(...)'
>>    msgqueue.cpp:190: warning: initialization to `FILE *' from `int' lacks
>a
>>cast
>>    msgqueue.cpp:192: warning: implicit declaration of function `int
>>pclose(...)'
>>
>>Here is the context:
>>  if( strlen(msgpackage.mtext) > 0 )
>>  {
>>    #ifdef _MYDEBUG
>>       cout << "Server: rcv: " << msgpackage.mtext << endl;
>>    #endif
>>       char cmdLine[MSGBUFSIZE+24];
>>       sprintf(cmdLine,"%s%s",cmdPing,msgpackage.mtext);
>>+     FILE* fp=popen(cmdLine,"r");
>>+     int iStatus=0;
>>+     switch( pclose(fp) ) // pclose returns the termination status of
>>cmdLine
>>       {
>>       case 0:
>>        iStatus = HOST_ALIVE;
>>        break;
>>       default:
>>        iStatus = HOST_DEAD;
>>       }
>>       sprintf( msgpackage.mtext +
>>strlen(msgpackage.mtext),"\t%s",STR_HOST_STATUS[iStatus] );
>>       msgpackage.mtype = SERVER_DATA;
>>       msgsnd( msg_id, (MSGStruct)&msgpackage, MSGBUFSIZE, 0);
>>      }
>>
>>It seems very clear that the "popen" and "pclose" are not declared in the
>>header file. However, they suppose to be declared in stdio.h and here is
my
>>includes:
>>    #include <sys/types.h>
>>    #include <sys/ipc.h>
>>    #include <sys/msg.h>
>>    #include <limits.h>
>>    #include <unistd.h>
>>    #include <syslog.h>
>>    #include <errno.h>
>>    #include <string.h>
>>    #include <stdio.h>
>>    #include <stdlib.h>
>>    #include <fstream.h>
>>    #include <iostream.h>
>>
>>I suspect that this is because that I primarily use C++ functions and
there
>>are some preprocess symbols need to be declared/cleared.  If it is the
>case,
>>how can I use popen in my C++ program in SUN OS with a probably obsoleted
>>g++ version???
>>
>>Once again, there is no any syntax and logical error when I run this
>program
>>on my Linux machine. However, I need it to be able to run on that stupid
>Sun
>>box as well - and worst of all, I am primary a Windows programmer.
>>
>>Any information will be very much appreciated! Please also reply to my
>>account at kevin@blueshoe.com .
>>
>>Thanks in advance,
>>Kevin
>>
>>
>>
>>
>>
>
>
Re: Why do I get warnings using popen in g++??? Help needed!
#3429
Author: Jim Cobban
Date: Mon, 23 Mar 1998 00:00
8 lines
955 bytes
You could try using pfstream.  I note that you are using a mixture of
conventional and stream I/O.
-- 
Jim Cobban   |  jcobban@nortel.ca                   |  Phone: (613) 763-8013
Nortel (MCS) |                                      |  FAX:   (613) 763-5199
|   "I am not a number.  I am a human being!"
|	P. McGoohan, "The Prisoner"
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads