30 Kasım 2020 Pazartesi

signed Anahtar Kelimesi

Giriş
C++ ile signed anahtar kelimesini kullanmak çoğunlukla isteğe bağlı, çünkü bir integral tipin varsayılan tipi signed. Ancak iki yerde istisna var. Açıklaması şöyle
There are at least two places where the signed keyword is not a no-op:
1. char Tipi
 Açıklaması şöyle
With char: the signedness of "plain" char is implementation-defined. On implementations where it's an unsigned type, signed char is needed to get the signed variant. Even if char is a signed type, signed char, char, and unsigned char are all distinct types.
Yani sadece char olarak kullanırsak signed char veya unsigned char olabilir. Tamamen derleyiciye bağlı

2. Bitfield Tipi
Açıklaması şöyle
With bitfields: bitfield members without explicit signedness have implementation-defined signedness.
Bitfield için elimizde şöyle bir kod olsun. b alanı signed veya unsigned olabilir. Tamamen derleyiciye bağlı
struct foo {
  int b:1;
};
Açıklaması şöyle
b may be { -1, 0 } or { 0, 1 } depending on the implementation

Hiç yorum yok:

Yorum Gönder