[Rd] Problem using ofstream in C++ class in package for MacOS X
cstrato
cstrato at aon.at
Mon Feb 5 19:48:17 CET 2007
Dear Jochen
Thank you, there seems to be a problem with accessing memory but
probably not in my simple program.
Here are the essential parts:
1. R-function:
"writeFileCpp" <-
function(outfile=character(0)) {
r <- .C("WriteFileCpp",as.character(outfile), PACKAGE="MyClass");
return();
}
2. R-wrapper:
void WriteFileCpp(char **outfile)
{
MyClassA *classA = new MyClassA();
classA->WriteFileCpp(outfile[0]);
delete classA;
}
3. C++ method:
void MyClassA::WriteFileCpp(const char *outfile)
{
ofstream output(outfile, ios::out);
output << 21 << endl;
output.close();
}
This crashes with "non-existent physical address"
Interestingly, the following C++ method works:
void MyClassA::WriteFileCpp(const char *outfile)
{
ofstream output(outfile, ios::out);
// output << 21 << endl;
output.close();
}
This means, that the operator "<<" seems to cause the problem, but why?
Best regards
Christian
Jochen Laubrock wrote:
> Hi cstrato,
>
>
> On 04.02.2007, at 22:47, cstrato wrote:
>
>> ostream.tcc
>>
>
>
> On my system (Mac OS X), ostream.tcc seems to be just a part of the
> FSF/GNU implementation of the stl, as
>
> head -n 40 /usr/include/c++/4.0.0/bits/ostream.tcc
>
> gives
>
>> // This file is part of the GNU ISO C++ Library. This library is free
>> // software; you can redistribute it and/or modify it under the
>> [...]
>> /** @file ostream.tcc
>> * This is an internal header file, included by other library headers.
>> * You should not attempt to use it directly.
>> */
>>
>> //
>> // ISO C++ 14882: 27.6.2 Output streams
>
>
> I think your error looks more like you are accessing invalid memory,
> maybe a dangling pointer ?
>
> hth, jochen
>
More information about the R-devel
mailing list