|
|
||||||
|
#1
|
|
|
|
|
I am using a C library in my C++ program. I open a file for reading
in binary populating a char buffer. I pass this buffer to the C funtion. When it is done I write the buffer to my ofstream file. I want this fucntion to work on 32bit and PPC 32bit systems as well as 64 bit systems. Any issues? Is the following ok? ----------------------------------------------------------------- bool ProcessFile(std::string sFileIn, std::string sFileOut) { // Will be set by library function unsigned char ucSpec[128]; /* open file for reading in binary mode */ std::ifstream infile; std::ofstream outfile; infile.open(sFileIn.c_str(), std::ios::in | std::ios::binary); outfile.open(sFileOut.c_str(), std::ios::out | std::ios::binary); /* set cursor to the beginning of the file */ infile.seekg(0, std::ios::beg); char buf[512]; // Write the ucSpec first outfile.write(reinterpret_cast<const char *>(ucSpec), 128); while (!infile.eof()) { infile.read(buf, sizeof(buf)); OldCFunction(reinterpret_cast<unsigned char *>(buf),cData,infile.gcount(),&pSpec); outfile.write(reinterpret_cast<const char *>(cData), infile.gcount()); } infile.close(); outfile.close(); return true; } |
|
|
|
#2
|
|
|
|
|
Hello NA,
> infile.read(buf, sizeof(buf)); > OldCFunction(reinterpret_cast<unsigned char > *>(buf),cData,infile.gcount(),&pSpec); > outfile.write(reinterpret_cast<const char *>(cData), This is the only thing that jumps out at me. What is cData? Can it safely be casted to a 64-bit const char*? If you're using Visual Studio 2003, you can enable the /Wp64 compiler switch, and it will warn for 64-bit-unsafe constructs. It doesn't catch as much as the 64-bit compiler does, but it gives you some idea. |
|
#3
|
|
|
|
|
"Kim Gräsman" <kim> wrote in message
>> infile.read(buf, sizeof(buf)); >> OldCFunction(reinterpret_cast<unsigned char >> *>(buf),cData,infile.gcount(),&pSpec); >> outfile.write(reinterpret_cast<const char *>(cData), > > This is the only thing that jumps out at me. What is cData? Can it safely > be casted to a 64-bit const char*? cData is declared as an unsigned char plaintext[512] |
|
#4
|
|
|
|
|
> cData is declared as an unsigned char plaintext[512]
That should read unsigned char cData[512] excuse me... |
|
|
| Similar Threads | |
| reinterpret_cast Per Stroustrup C++ Glossary ([..] glossary.html#Greinterpret_cast) reinterpret_cast - a type conversion operation that reinterprets the raw memory of an object as a value of... |
|
| reinterpret_cast I am trying to understand reinterpret_cast,here is what i tried, #include<iostream> #include<cstdio> using namespace std; int main() { int x=1; int* y=&x; |
|
| reinterpret_cast<> and UB I have: // base class for Vector and Matrix template <unsigned N,typename Value=float> class NonScalar { public: Value *ptr() { return e; } const Value *ptr() const {... |
|
| reinterpret_cast Hello. Is it possible to convert a pointer to function into int? void fun(); int main() { reinterpret_cast<int>(fun); } |
|
| reinterpret_cast<> Hi, wrote this piece of code on SunOS 5.9 , compiler g++ 2.95.3 trying to see the byte order of an int or short int by converting to char* . doesn't work . the char* cpt... |
|
|
All times are GMT. The time now is 01:34 AM. | Privacy Policy
|