Connecting Tech Pros Worldwide Help | Site Map

Porting old non ansi code

  #1  
Old July 22nd, 2005, 07:48 AM
TheDD
Guest
 
Posts: n/a
Hello all,

i've downloaded the source code of a GPL project but i don't manage to
compile it.

It have been written with an old g++ (<3) since there are #include <xxx.h>
and no std:: at all... In addition, all the C++ file extensions are '.C'
and '.h', makefile c++ compiler variable is "CC" with "CC-FLAGS"...

But others problems are harder to solve. For example, i have:

src/rec/Train.C: In member function `void Train::WriteTrainingFile(const
char*)':
src/rec/Train.C:272: aggregate `std::filebuf fbuff' has incomplete type and
cannot be defined

with:

272 filebuf fbuff;
273 fbuff.open( path, ios::out );
274 ostream out( &fbuff );

I don't see any problem...

Also, a g++ extension seems to be used: the "form()" function wich is used
like that:

out << form( TD_VersionFormat, TD_Version )

Do you know a macro i could define using ansi c++ so that the code can
compile?

I would like to correct the code and submit a path to these great searchers
but really poor programmers...

Thx by advance

--
TheDD
  #2  
Old July 22nd, 2005, 07:48 AM
John Harrison
Guest
 
Posts: n/a

re: Porting old non ansi code



"TheDD" <pas.d@email.com> wrote in message
news:cwyeoy4j33qz$.36kshb56pr5b.dlg@40tude.net...[color=blue]
> Hello all,
>
> i've downloaded the source code of a GPL project but i don't manage to
> compile it.
>
> It have been written with an old g++ (<3) since there are #include <xxx.h>
> and no std:: at all... In addition, all the C++ file extensions are '.C'
> and '.h', makefile c++ compiler variable is "CC" with "CC-FLAGS"...
>
> But others problems are harder to solve. For example, i have:
>
> src/rec/Train.C: In member function `void Train::WriteTrainingFile(const
> char*)':
> src/rec/Train.C:272: aggregate `std::filebuf fbuff' has incomplete type[/color]
and[color=blue]
> cannot be defined
>
> with:
>
> 272 filebuf fbuff;
> 273 fbuff.open( path, ios::out );
> 274 ostream out( &fbuff );
>
> I don't see any problem...[/color]

Most likely a missing header file. Try

#include <fstream>
using namespace std;
[color=blue]
>
> Also, a g++ extension seems to be used: the "form()" function wich is used
> like that:
>
> out << form( TD_VersionFormat, TD_Version )
>
> Do you know a macro i could define using ansi c++ so that the code can
> compile?[/color]

Can't see why the above wouldn't compile, assuming form is defined.

john


  #3  
Old July 22nd, 2005, 07:48 AM
TheDD
Guest
 
Posts: n/a

re: Porting old non ansi code


On Mon, 23 Feb 2004 22:06:41 -0000, John Harrison wrote:
[color=blue]
> Most likely a missing header file. Try
>
> #include <fstream>
> using namespace std;[/color]

yes, it works now, thx :)
[color=blue]
> Can't see why the above wouldn't compile, assuming form is defined.[/color]

well form() doesn't seems to be defined. I believe it's an old extension of
g++ wich has been deleted. But since i don't know the STL enough, i don't
know how to emulate the form() function.

--
TheDD
  #4  
Old July 22nd, 2005, 07:48 AM
John Harrison
Guest
 
Posts: n/a

re: Porting old non ansi code



"TheDD" <pas.d@email.com> wrote in message
news:1xq5edlc8hnqv$.1tw7tgtw7wzyc$.dlg@40tude.net. ..[color=blue]
> On Mon, 23 Feb 2004 22:06:41 -0000, John Harrison wrote:
>[color=green]
> > Most likely a missing header file. Try
> >
> > #include <fstream>
> > using namespace std;[/color]
>
> yes, it works now, thx :)
>[color=green]
> > Can't see why the above wouldn't compile, assuming form is defined.[/color]
>
> well form() doesn't seems to be defined. I believe it's an old extension[/color]
of[color=blue]
> g++ wich has been deleted. But since i don't know the STL enough, i don't
> know how to emulate the form() function.
>[/color]

I've never heard of it, I don't think its ever been official STL. Taking a
wild guess it might be an attempt to do printf style formatting in an
iostream context, but I would ask on a gcc group to find out for certain.

john


  #5  
Old July 22nd, 2005, 07:48 AM
David Mancel
Guest
 
Posts: n/a

re: Porting old non ansi code


On Mon, 23 Feb 2004 22:30:03 -0000, John Harrison wrote:
[color=blue]
> "TheDD" <pas.d@email.com> wrote in message
> news:1xq5edlc8hnqv$.1tw7tgtw7wzyc$.dlg@40tude.net. ..[color=green]
>> On Mon, 23 Feb 2004 22:06:41 -0000, John Harrison wrote:
>>[color=darkred]
>>> Most likely a missing header file. Try
>>>
>>> #include <fstream>
>>> using namespace std;[/color]
>>
>> yes, it works now, thx :)
>>[color=darkred]
>>> Can't see why the above wouldn't compile, assuming form is defined.[/color]
>>
>> well form() doesn't seems to be defined. I believe it's an old extension[/color]
> of[color=green]
>> g++ wich has been deleted. But since i don't know the STL enough, i don't
>> know how to emulate the form() function.
>>[/color]
>
> I've never heard of it, I don't think its ever been official STL. Taking a
> wild guess it might be an attempt to do printf style formatting in an
> iostream context, but I would ask on a gcc group to find out for certain.[/color]

it's sure:
http://www.geocrawler.com/archives/3...2/7/0/2055820/


my hack:
string form(const char *fmt, ...)
{
char tmp[2048];
va_list ap;
int res;

va_start(ap, fmt);
res = vsnprintf(tmp, 2046, fmt, ap);
va_end(ap);

return string(tmp);
}


--
David Mancel
SCIA 2005
  #6  
Old July 22nd, 2005, 07:48 AM
TheDD
Guest
 
Posts: n/a

re: Porting old non ansi code


On Mon, 23 Feb 2004 22:30:03 -0000, John Harrison wrote:
[color=blue]
> I've never heard of it, I don't think its ever been official STL. Taking a
> wild guess it might be an attempt to do printf style formatting in an
> iostream context, but I would ask on a gcc group to find out for certain.
>
> john[/color]

it's sure:
http://www.geocrawler.com/archives/3...2/7/0/2055820/


my hack:
string form(const char *fmt, ...)
{
char tmp[2048];
va_list ap;
int res;

va_start(ap, fmt);
res = vsnprintf(tmp, 2046, fmt, ap);
va_end(ap);

return string(tmp);
}

--
TheDD
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
ANSI C compliance Roose answers 100 February 6th, 2006 11:25 PM
C portability is a myth roman ziak answers 93 November 14th, 2005 07:38 PM
Future reuse of code James Cameron answers 253 November 13th, 2005 05:44 PM
Future reuse of code James Cameron answers 242 July 19th, 2005 05:48 PM