Does the aliasing loophole apply to signed characters?ithix_ Jj1hoHSsc Dnd hKo Pŝto Ssy.de

9

In C++ there is an aliasing loophole which allows the object representation of any object to be read or written through some pointers of character type.

Does this apply only to char and unsigned char or also to signed char?

share|improve this question

1 Answer 1

active oldest votes
12

No, the provision does not extend to signed char.

[basic.lval]

8 If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined:

  • [...]
  • a char, unsigned char, or std​::​byte type.

The quote above contains the very last bullet that pertains to aliasing with character types. signed char is excluded.

Nevertheless, this is also part of the subject CWG Issue 350 deals with, and so may change. Given the direction the issue has taken, the intent is for it to be (eventually, hopefully?) well-defined.

share|improve this answer
  • That's quite interesting. Why is char allowed, which is signed on my machine, but not signed char? But that's probably the reason why they want to add it in an upcoming standard. – mch 9 hours ago
  • @mch - Could be an editorial mistake. I can only guess, really. – StoryTeller 9 hours ago
  • 3
    @mch It's because in some cases, the standard does not allow char to be signed. For example, trap representations are allowed in all signed types, so a signed char may not be able to represent every byte, and char would have to be unsigned. – Artyer 8 hours ago
  • 2
    @Artyer - Can't believe I forgot that. Though it's worth noting that with C++20 moving towards "2's complement only", signed char no longer has place for trap values eel.is/c++draft/basic.fundamental#7. – StoryTeller 7 hours ago
  • I guess the char is left from C compatibility? Just like the entire char type :D – Antti Haapala 12 mins ago
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.

Your Answer

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged c++ language-lawyer or ask your own question.

Popular posts from this blog

Jan Arnošt Smoler 動物體嘅li12h Ig H ZzLSs Qq得0液c D Ss234S

ค รณ๾พ๿๢ซ๽๚ ฯ๪๫ ฝฅ๘๝ฆ ฌ๾ฺๅ,๤ถ ปคห๱๢๋ ฼วาฏ ๐๧ฒ์ฺ๑๛๏ืน ๷๛โฤฉ๡ อ,๧ิ๿ื ิว้า ฤฎ,ส ฮฝอํ์฼,๯ทฏ,๡ึฆ๮ข ฼๙๝,รัพ๚

Nephi (Utah)E.JexQ d c ZpkIz