Wird static_cast garantiert einen Wert an 0 oder 1 senden?C++

Programme in C++. Entwicklerforum
Anonymous
 Wird static_cast garantiert einen Wert an 0 oder 1 senden?

Post by Anonymous »

Ich versuche, ein Problem zu untersuchen, bei dem ein Datenbank -Treiber erwartet, dass ein bestimmtes uint8_t Mitglied in einer Struktur 0 oder 1 . Ich glaube, dass dies manchmal Werte ungleich Null für true anstelle von dem Wert 1 . In C ++ bietet static_cast < /code> eine ähnliche Garantie oder erfordert dies so etwas wie den C-Trick?

Code: Select all

#include 
#include 

template
struct TVector {
std::vector data;

void Append(const T& value){
data.push_back(value);
}
};

struct source {
//other members

// Note that this is from shared memory, 'true' could have extra junk
// besides just the literal value '1'
bool is_final;

//other members
};

struct worker {

void append(const source& source) {
// At some point is_final wasn't a bool, which is I believe
// why this static cast is here.
data.Append(static_cast(source.is_final));
}

TVector data;
};

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post