standards

printf conversion specifier for _Bool?

拥有回忆 提交于 2019-12-09 14:31:07
问题 With printf() , I can use %hhu for unsigned char , %hi for a short int , %zu for a size_t , %tx for a ptrdiff_t , etc. What conversion format specifier do I use for a _Bool ? Does one exist in the standard? Or do I have to cast it like this: _Bool foo = 1; printf("foo: %i\n", (int)foo); 回答1: There is no specific conversion length modifier for _Bool type. _Bool is an unsigned integer type large enough to store the values 0 and 1 . You can print a _Bool this way: _Bool b = 1; printf("%d\n", b);

Visual C++ standards compliance [closed]

ぐ巨炮叔叔 提交于 2019-12-09 14:29:02
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I was wondering if, and to what degree, does Microsoft's Visual C++ compiler conform to the current C (C90/C99) and C++ (ISO/IEC 14882

Pointer arithmetic and integral promotion

為{幸葍}努か 提交于 2019-12-09 12:38:33
问题 In the expression p + a where p is a pointer type and a is an integer, will integer promotion rules apply? For example, if a is a char , on a 64-bit machine it will surely be extended to 64 bit before being added to the pointer value (in the compiled assembly), but is it specified by the standards? What will it be promoted to? int , intptr_t or ptrdiff_t ? What will unsigned char or size_t be converted to? 回答1: It does not seem required by the standard for any promotion to occur since char is

What are the differences between the C and C++ preprocessors? [duplicate]

自作多情 提交于 2019-12-09 10:06:34
问题 This question already has answers here : Is a C++ preprocessor identical to a C preprocessor? (3 answers) Closed 5 years ago . Are there any differences in behaviour between the C and C++ preprocessors? They are defined by different passages of standards text (section 6.10 of the C standard and section 16 of the C++ standard). My motivation for asking this is that a proposal for making the single quote a digit separator that was recently accepted into C++14 extends the C++ preprocessor

HTML version of C standard draft (n1256.pdf)?

谁说胖子不能爱 提交于 2019-12-09 08:21:46
问题 Is there an HTML version of n1256.pdf (ISO C99+TC3), or a recommended way to convert it to html or another less-painful format for browsing? All of the pdf converters I've tried have given very poor results, especially in failing to convert the "fi" ligatures to something more easily searchable, but also just with respect to basic formatting. Here is the original for reference: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf 回答1: It seems to be the last draft prior to

Passing a pointer to a member function as a template argument. Why does this work?

久未见 提交于 2019-12-09 07:50:40
问题 I have some code that 100% works for the use case I have. I'm just wondering if anyone can explain how and why it works. I have a template class that sits between some code that handles threading and network communication and the library user to pass data received from the server to the user. template <class Bar, class Baz, class BazReturnType, void (Bar::*BarSetterFunction)(const BazReturnType &), BazReturnType (Baz::*BazGetterFunction)(void) const> class Foo { Foo( Bar *bar ) : m_bar(bar) {

Should this be ambiguous or not? (implicit casts)

↘锁芯ラ 提交于 2019-12-09 07:46:25
问题 struct A { A(const A& src); A(const char* src); }; struct B { operator A(); operator char*(); }; void test() { B v; A s(v); } EDG/Comeau and MSVC allows the code while GCC 4.4.4, CLANG and BCC reject it as ambiguous. A C++ committee member replied with this (initially): It's not ambiguous; the A(const A&) constructor is better than the A(const char*) constructor. The const A& parameter binds directly to the result of the conversion function, so the conversion sequence is considered to be a

What is the behavior of writing a non-printing character in C/C++?

末鹿安然 提交于 2019-12-09 03:23:56
问题 Is the behavior of writing a non-printing character undefined or implementation-defined, if the character is written via printf / fprintf ? I am confused because the words in the C standard N1570/5.2.2 only talks about the display semantics for printing characters and alphabetic escape sequences. In addition, what if the character is written via std::ostream (C++ only)? 回答1: The output of ASCII non-printable (control) characters is implementation defined. Specifically, interpretation is the

What is the longest possible email address? [duplicate]

家住魔仙堡 提交于 2019-12-09 02:15:24
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Exceeding Max Email Address Sizes Is there a technical limitation to how long email addresses can be? Are there practical limitations imposed by the different major email providers out there (Google, Microsoft, etc.)? De jure or de facto, is there a limit on the number of characters in an email address? 回答1: What is the maximum length of an email address? 254 characters "This arises from the simple arithmetic of

Is the: “std::string can hold '\0' character” by design?

风流意气都作罢 提交于 2019-12-08 17:28:16
问题 The fact that std::string can actually hold '\0' characters comes up all the time. This is of course inconsistent with C-style strings. So I'm wondering, is this by design, or is it an omission, or is it just the fact that standard doesn't forbid it and compilers allow this to happen? 回答1: I'm wondering what your quarrel is. '\0' is just another character. There is no efficient way to forbid it in a general purpose 'char' string. That the same character has a special meaning in C is