*BSD News Article 77451


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.rmit.EDU.AU!news.unimelb.EDU.AU!munnari.OZ.AU!news.mel.connect.com.au!news.mira.net.au!news.vbc.net!news.leonardo.net!news.cyberport.com!news.supernet.net!news.magicnet.net!news.sprintlink.net!news-fw-6.sprintlink.net!news.sprintlink.net!news-fw-12.sprintlink.net!news.sprintlink.net!new-news.sprintlink.net!metro.atlanta.com!cssun.mathcs.emory.edu!gatech!news.mathworks.com!newsfeed.internetmci.com!howland.erols.net!mcsun!EU.ne
t!usenet2.news.uk.psi.net!uknet!usenet1.news.uk.psi.net!uknet!dispatch.news.demon.net!demon!awfulhak.demon.co.uk!awfulhak.demon.co.uk!awfulhak.demon.co.uk!not-for-mail
From: brian@awfulhak.demon.co.uk (Brian Somers)
Newsgroups: comp.unix.bsd.freebsd.misc,gnu.g++.help
Subject: Re: g++2.7.2 error on freebsd
Followup-To: comp.unix.bsd.freebsd.misc,gnu.g++.help
Date: 2 Sep 1996 11:48:15 +0100
Organization: Coverform Ltd.
Lines: 68
Distribution: world
Message-ID: <50ee1f$dp@anorak.coverform.lan>
References: <8414360547401@maverick.mcs.anl.gov>
NNTP-Posting-Host: localhost.coverform.lan
X-NNTP-Posting-Host: awfulhak.demon.co.uk
X-Newsreader: TIN [version 1.2 PL2]
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:26570 gnu.g++.help:13212

Satish Balay (balay@maverick.mcs.anl.gov) wrote:

: 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
: (balay@mcs.anl.gov)
: ----------------------------------------


: #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;
}

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

--
Brian <brian@awfulhak.demon.co.uk>
Don't _EVER_ lose your sense of humour....