は、G ++ 4.8.2(32ビットSTD = C++ 98)との大規模なレガシーアプリケーションを再コンパイルは、新しい警告は、Gに警告なしにコンパイルwarning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
Cの文字列へのC++参照は可能ですか?
コードを言っデータシリアライザの部分から飛び出し++ 4.4 。7。
この警告は、「char &」をシリアライズするテンプレート関数から得られます。コメントには、NULLで終了する文字列への参照が含まれています。
私はC++を初めて使っています...はありませんconst char&
1文字への参照ですか? Cのヌル終了文字列の開始アドレスとしてこの参照を使用しないのは、ある種の不正行為ですか?
警告を無視するか、そうでない場合は、この構成に適切なフォーム(存在する場合)は何ですか?
//! Implementations of write() for null-terminated strings.
void write(DvCsr::TName, const char* v, long = NO_INDEX) {writeCStr(v);}
void write(DvCsr::TName, const u_char* v, long = NO_INDEX) {writeCStr(v);}
void write(DvCsr::TName, const char& v, long = NO_INDEX) {writeRefCStr(v);}
void write(DvCsr::TName, const u_char& v, long = NO_INDEX) {writeRefCStr(v);}
//! Write null-terminated string data types to the stream.
template <class T>
void writeCStr(const T* start)
{
// Find length of the string, not including null terminator,
// and size (in bytes), including null terminator.
const T* end = start;
while (*end++)
;
size_t len = end - start;
// Add the string to the end of the buffer.
mBuffer.reserve(mBuffer.size() + len);
std::copy(start, start + len, std::back_inserter(mBuffer));
};
template <class T>
void writeRefCStr(const T &start)
{
writeCStr((unsigned char *)start);
}
良いルール:警告を無視して常に '-pedantic -Wall'でコンパイルしないでください – Rakete1111
@ Rakete1111' -Wextra'を(少なくとも)それに追加します。 –
@JesperJuhlこの場合、 '-pedantic-errors -Werror'も追加します:P – Rakete1111