2016-11-25 12 views
0

私はVisual Studio 2015を使用していますが、この環境では数ヶ月しか使用できません。私はC++とCの経験を持っています。Visual Studio:ウォッチウィンドウ:C++:なぜchar型メンバーのガーベジですか?

以下のコードを実行して、デバッガのウォッチウィンドウからtmpクラスのメンバをチェックすると、char型とunsigned char型メンバの値の列にガベージがいくつか見えます。

この現象が起こると、ウォッチウィンドウのスクリーンショットが添付されました。

enter image description here

例:

clock_class 1 '\x1' unsigned char 
priority2 248 '・' unsigned char 
log_sync_interval -3 '' char 
log_announce_interval 0 '\0' char 

この問題が発生したのはなぜ? これはVisual Studioの仕様ですか、私のコードは何か問題がありますか? 私の理解では、C++はchar型を8bit変数、 として扱います。なぜこのようなことが起こるのだろうかと思います。

------------------------------------------------------- 
Code: 

#include "stdafx.h" 
#include "stdint.h" 

struct test_class{ 
public: 
    uint16_t descriptor_index; 
    uint16_t localized_description; 
    uint64_t mac_address; 
    uint16_t interface_flags; 
    uint64_t clock_identity; 
    uint8_t priority1; 
    uint8_t clock_class; 
    uint16_t offset_scaled_log_variance; 
    uint8_t clock_accuracy; 
    uint8_t priority2; 
    uint8_t domain_number; 
    int8_t log_sync_interval; 
    int8_t log_announce_interval; 
    int8_t log_pdelay_interval; 
    uint16_t port_number; 
}; 

int main() 
{ 
    test_class * tmp = new test_class; 

    tmp->descriptor_index = 0; 
    tmp->localized_description = 65535; 
    tmp->mac_address = 0x22970405b7; 
    tmp->interface_flags = 0x7; 
    tmp->clock_identity = 0x2297fffe0405b7; 
    tmp->priority1 = 0; 
    tmp->clock_class = 1; 
    tmp->offset_scaled_log_variance = 17258; 
    tmp->clock_accuracy = 32; 
    tmp->priority2 = 248; 
    tmp->domain_number = 0; 
    tmp->log_sync_interval = -3; 
    tmp->log_announce_interval = 0; 
    tmp->log_pdelay_interval = 0; 
    tmp->port_number = 1; 

<- Break at here and watch members of tmp 

    delete tmp; 

    return 0; 
} 

------------------------------------------------------- 
+3

値は、 '」「'内部のシンボル正しいですが、この値が表すcharactです –

答えて

1

uint8_tは、デバッガは、単一引用符の間char値を示している理由であり、0から255まで缶(通常)店値unsigned char型の別名です。むしろ文字を表示しようとすると、この値(数値)に相当します。いないすべての値が文字として印刷することができ、はゴミとして表示されます:

for (uint8_t i = 0; i < 255; i++) 
{ 
    std::cout << uint8_t(i); 
} 
関連する問題