g++2.7.2 error on freebsd

g++2.7.2 error on freebsd

Post by Satish Bal » Sat, 31 Aug 1996 04:00:00



Hi,

        I tried to compile this code on freebsd, and it dos'nt compile..
        What am I doing wrong? I'm using g++ -v 2.7.2

        I tried compiling using g++ 2.7.2 on sunOS and linux and other
        c++ compilers,and it works correctly..

        Any pointers would be helpful..

        Thanks

Satish Balay

----------------------------------------

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

int NewPrintf(char *format,...)
{
  int rank;
  va_list Argp;
  FILE *fp;

  fp = fopen("x","w");
  va_start( Argp, format );
  vfprintf(fp,(char *)format,(void *)Argp);
  va_end( Argp );
  fflush(stdout);
  return 0;

Quote:}

 
 
 

g++2.7.2 error on freebsd

Post by Max Welto » Sat, 31 Aug 1996 04:00:00



> Hi,

>         I tried to compile this code on freebsd, and it dos'nt compile..
>         What am I doing wrong? I'm using g++ -v 2.7.2

Could you post the output?

 
 
 

g++2.7.2 error on freebsd

Post by L. Felaw » Mon, 02 Sep 1996 04:00:00



 >
 >Hi,
 >
 >        I tried to compile this code on freebsd, and it dos'nt compile..
 >        What am I doing wrong? I'm using g++ -v 2.7.2

It works for me, but gives compiler warning:

  foo.cc: In function `int NewPrintf(char * ...)':
  foo.cc:14: warning: ANSI C++ forbids implicit conversion from `void *'
             in argument passing

I am using gcc-2.7.2 (with "repo-bsd" and "no-weak-support" patches
applied) and libg++-2.7.1 (compiled with gcc-2.7.2, of course).

_____
Larry

 
 
 

g++2.7.2 error on freebsd

Post by Brian Some » Tue, 03 Sep 1996 04:00:00


: Hi,

:         I tried to compile this code on freebsd, and it dos'nt compile..
:         What am I doing wrong? I'm using g++ -v 2.7.2

:         I tried compiling using g++ 2.7.2 on sunOS and linux and other
:         c++ compilers,and it works correctly..
:        
:         Any pointers would be helpful..

:         Thanks

: Satish Balay

: ----------------------------------------

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

: int NewPrintf(char *format,...)
: {
:   int rank;
:   va_list Argp;
:   FILE *fp;

:   fp = fopen("x","w");
:   va_start( Argp, format );
:   vfprintf(fp,(char *)format,(void *)Argp);
:   va_end( Argp );
:   fflush(stdout);
:   return 0;
: }

Hmm, it couldn't work correctly - it doesn't close fp - or check to see if
it actually opened "x".  And why is it flushing stdout ?

The correct code, I suspect, is:

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

int NewPrintf( char *format, ... )
{
  int rank;
  va_list Argp;
  FILE *fp;

  if( fp = fopen( "x", "w" ), !fp )
    return 1;
  va_start( Argp, format );
  vfprintf( fp, (char *)format, Argp );
  va_end( Argp );
  fclose( fp );
  return 0;

Quote:}

This works on 2.6.3 - dunno about 2.7.2 - if it doesn't compile, you've got
a duff gcc build !

--

Don't _EVER_ lose your sense of humour....

 
 
 

g++2.7.2 error on freebsd

Post by Satish Bal » Wed, 04 Sep 1996 04:00:00





> >Hi,

> >        I tried to compile this code on freebsd, and it dos'nt compile..
> >        What am I doing wrong? I'm using g++ -v 2.7.2

>It works for me, but gives compiler warning:

>  foo.cc: In function `int NewPrintf(char * ...)':
>  foo.cc:14: warning: ANSI C++ forbids implicit conversion from `void *'
>             in argument passing

>I am using gcc-2.7.2 (with "repo-bsd" and "no-weak-support" patches
>applied) and libg++-2.7.1 (compiled with gcc-2.7.2, of course).

Ho do I fix my code so that these warnings do not occur..

Or is there a bug in the includefiles that flags such a usage as error.
Otherplatforms like sun4,linux using gcc-2.7.2, I do not get this warning..

Thanks.

Satish

 
 
 

g++2.7.2 error on freebsd

Post by J Wuns » Fri, 06 Sep 1996 04:00:00



> Or is there a bug in the includefiles that flags such a usage as error.
> Otherplatforms like sun4,linux using gcc-2.7.2, I do not get this warning..

The assembler and linker do not handle .weak symbols in FreeBSD yet.
GNU ld doesn't support FreeBSD ``out of the box''.

If you run FreeBSD 2.2-current, you might give John Polstra's
``elfkit'' a try -- the ELF environment for GNU as and ld should work
without modifications.

--
cheers, J"org


Never trust an operating system you don't have sources for. ;-)

 
 
 

g++2.7.2 error on freebsd

Post by Mike Harro » Mon, 09 Sep 1996 04:00:00



[snip]

: Hmm, it couldn't work correctly - it doesn't close fp - or check to see if
: it actually opened "x".  And why is it flushing stdout ?

: The correct code, I suspect, is:

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

: int NewPrintf( char *format, ... )
: {
:   int rank;
:   va_list Argp;
:   FILE *fp;

:   if( fp = fopen( "x", "w" ), !fp )
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ARGHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH! :-)

:     return 1;
:   va_start( Argp, format );
:   vfprintf( fp, (char *)format, Argp );
:   va_end( Argp );
:   fclose( fp );
:   return 0;
: }

I have simpler questions... why is he using FILEs? Why is he using C header
files (eg <stdlib.h>) and not C++ header files (eg <cstdlib>)?

/Mike

--
+--------------------------------------------------------------------------+
| Take the cheese to sickbay, the Doctor should take a look at it as soon  |
| as possible.  --  B'lanna Torres - Star Trek Voyager - 'Learning Curve'. |
+--------------------------------------------------------------------------+

 
 
 

g++2.7.2 error on freebsd

Post by Satish Bal » Mon, 09 Sep 1996 04:00:00




>I have simpler questions... why is he using FILEs? Why is he using C header
>files (eg <stdlib.h>) and not C++ header files (eg <cstdlib>)?

I'm working on a project which involves developing numerical
libraries. We do the coding in "c", and provide stubs for
it to be useable from C++ and fortran. Since most of
"c" compiles in "c++", the stubbs of "c++" are provided
using #define, and by compiling with c++ compiler.
Since c++ compiler is supporsed to work with stdio.h, stdlib.h, we use them.
Till now we did'nt whave any problems with this. We were using
eariler versions of gcc/g++ (On various platforms like sun4,
LINUX, freebsd, DEC alpha It also works on other platforms
like IRIX, IBM rs6000, solaris etc... whre we use native
c , c++ compilers.). But on freebsd using g++2.7.2, we get this strange
warinig message, which dos'nt occur on ANY OTHER PRATFORM (other compilers,
older versions of g++, g++2.7.2 on sun4, LINUX, DEC alpha). This
kinad of sugests that either g++-2.7.2 on freebsd is screwed up,
or they implemented a new feature of C++ not implemneted on g++2.7.2
on other arch. In either case, how do i get rid of this warning message?

The code i posted was just a cut out form this project. I added a few
things ( Like the FILE stuff) so that it compiles standalone.
I have a new cut without the FILE stuff which gives the same warnings.

Thanks for the help.

Satish

----------
#include <stdio.h>
#include <stdarg.h>

int NewPrintf(char *format,...)
{
  int rank;
  va_list Argp;

  va_start( Argp, format );
  vfprintf(stdout,format,Argp);
  va_end( Argp );
  fflush(stdout);
  return 0;

Quote:}

int main ()
{
  int a=10, b=20,c=30;
  NewPrintf( "A = %d B = %d C = %d\n",a,b,c);
  return 0;
Quote:}

------------------
elvis:/home/balay/junk>!g++
g++ printf.c
printf.c: In function `int NewPrintf(char * ...)':
printf.c:11: warning: ANSI C++ forbids implicit conversion from `void *' in argument passing
elvis:/home/balay/junk>a.out
A = 10 B = 20 C = 30
-------------------
 
 
 

g++2.7.2 error on freebsd

Post by Vlad » Mon, 09 Sep 1996 04:00:00




>  >Hi,

>  >        I tried to compile this code on freebsd, and it dos'nt compile..
>  >        What am I doing wrong? I'm using g++ -v 2.7.2

> It works for me, but gives compiler warning:

>   foo.cc: In function `int NewPrintf(char * ...)':
>   foo.cc:14: warning: ANSI C++ forbids implicit conversion from `void *'
>              in argument passing

> I am using gcc-2.7.2 (with "repo-bsd" and "no-weak-support" patches
> applied) and libg++-2.7.1 (compiled with gcc-2.7.2, of course).

        The problem seems to be in how the type of va_list is defined. It was
char* in v2.6.3 I believe but ends up void* in v2.7.2 when installed on
FreeBSD. You could fix it either in the appropriate .h-file or by coding
something like

#if (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
  vsprintf (fmt, (char *)ap);
#else
  vsprintf (buf, fmt, ap);
#endif

to be able to go between v2.6.3 and v2.7.2 at will. However, I noticed
that v2.7.2 installed on, say, OSF/1 v3.2 has no problems with va_list,
so maybe you should also check whether you're compiling on FreeBSD or
not in the first #if ...

Vlad.

 
 
 

g++2.7.2 error on freebsd

Post by Jordan K. Hubbar » Mon, 09 Sep 1996 04:00:00



> c , c++ compilers.). But on freebsd using g++2.7.2, we get this strange
> warinig message, which dos'nt occur on ANY OTHER PRATFORM (other

I think you're suffering from compiler technology which is simply
integrated incompletely into FreeBSD on your site.  We don't support
2.7.2, we support 2.6.3, and that means that many assumptions will be
made by the header files, libraries, etc. which are incompatible with
2.7.x and cannot be made otherwise without some knowledgeable system
integration work.  Fortunately for you, we've finally freed up some time
and resources and will be bringing 2.7.x into 2.2-current very shortly.
If you don't already subscribe to the cvs-all mailing list, I suggest

I also suggest that you wait an additional week after integration to
allow us to shake out the obvious problems, then upgrade yourself to
2.2-current.
--
- Jordan Hubbard
  President, FreeBSD Project

 
 
 

g++2.7.2 error on freebsd

Post by Brian Some » Tue, 10 Sep 1996 04:00:00




: [snip]

: : Hmm, it couldn't work correctly - it doesn't close fp - or check to see if
: : it actually opened "x".  And why is it flushing stdout ?

: : The correct code, I suspect, is:

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

: : int NewPrintf( char *format, ... )
: : {
: :   int rank;
: :   va_list Argp;
: :   FILE *fp;

: :   if( fp = fopen( "x", "w" ), !fp )
:     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

: ARGHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH! :-)

Pardon ?

: :     return 1;
: :   va_start( Argp, format );
: :   vfprintf( fp, (char *)format, Argp );
: :   va_end( Argp );
: :   fclose( fp );
: :   return 0;
: : }

: I have simpler questions... why is he using FILEs? Why is he using C header
: files (eg <stdlib.h>) and not C++ header files (eg <cstdlib>)?

Eh, 'cos it's C code ?

--

Don't _EVER_ lose your sense of humour....

 
 
 

g++2.7.2 error on freebsd

Post by m.. » Thu, 12 Sep 1996 04:00:00



> : :   if( fp = fopen( "x", "w" ), !fp )
> :     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> : ARGHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH! :-)

> Pardon ?

That seems like a comment on that rather baroque coding style. :-) It
is certainly not the most obvious way of saying

        if( !(fp=fopen("x", "w")) )

.

 
 
 

g++2.7.2 error on freebsd

Post by Brian Some » Fri, 13 Sep 1996 04:00:00



: > : :   if( fp = fopen( "x", "w" ), !fp )
: > :     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: >
: > : ARGHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH! :-)
: >
: > Pardon ?

: That seems like a comment on that rather baroque coding style. :-) It
: is certainly not the most obvious way of saying

:         if( !(fp=fopen("x", "w")) )

Hmm, I ended up doing this because I needed my code to compile on stupid
DOS compilers that warn about

    if( fp = fopen( "x", "w" ) )
    {
        ....
        fclose( fp );
    }

I like it :)

--

Don't _EVER_ lose your sense of humour....

 
 
 

g++2.7.2 error on freebsd

Post by Bruce Eva » Sat, 14 Sep 1996 04:00:00




>...
>c , c++ compilers.). But on freebsd using g++2.7.2, we get this strange
>warinig message, which dos'nt occur on ANY OTHER PRATFORM (other compilers,
>older versions of g++, g++2.7.2 on sun4, LINUX, DEC alpha). This
>kinad of sugests that either g++-2.7.2 on freebsd is screwed up,
>or they implemented a new feature of C++ not implemneted on g++2.7.2
>on other arch. In either case, how do i get rid of this warning message?
>...

gcc-2.7.2 isn't really supported on FreeBSD yet.  The gcc-2.7.2
distribution misconfigures some things.

Quote:>----------
>#include <stdio.h>
>#include <stdarg.h>

>int NewPrintf(char *format,...)
>{
>  int rank;
>  va_list Argp;

>  va_start( Argp, format );
>  vfprintf(stdout,format,Argp);
>  va_end( Argp );
>  fflush(stdout);
>  return 0;
>}

>int main ()
>{
>  int a=10, b=20,c=30;
>  NewPrintf( "A = %d B = %d C = %d\n",a,b,c);
>  return 0;
>}
>------------------
>elvis:/home/balay/junk>!g++
>g++ printf.c
>printf.c: In function `int NewPrintf(char * ...)':
>printf.c:11: warning: ANSI C++ forbids implicit conversion from `void *' in argument passing
>elvis:/home/balay/junk>a.out
>A = 10 B = 20 C = 30
>-------------------

This occurs because va_list is of type `void *', but vfprintf()'s third
arg is of type `_BSD_VA_LIST_' = `char *'.  _BSD_VA_LIST_ is a macro
that is supposed to give the same type as va_list.  gcc's stdarg.h
attempts to support this macro but gets it completely wrong.  First,
it is misspelled as _BSD_VA_LIST, so the system macro is unaffected.
Second, it is impossible to change the system type to match gcc's type
by supplying a modified <stdarg.h> - either <machine/stdarg.h> must
be modified, or gcc's type must be changed to match the system type.
Third, it #undef's _BSD_VA_LIST, but #undef'ing it would break <stdio.h>
if it were spelled correctly.  (It is used in <stdio.h> to avoid the
namespace pollution that would occur if <stdarg.h> were included.)

There are many other similarly trivial configuration problems.
--