Questions tagged [standards-compliance]

400 questions
52
votes
5 answers

Can a destructor be recursive?

Is this program well-defined, and if not, why exactly? #include #include struct X { int cnt; X (int i) : cnt(i) {} ~X() { std::cout << "destructor called, cnt=" << cnt << std::endl; if ( cnt-- >…
Cubbi
  • 46,567
  • 13
  • 103
  • 169
47
votes
7 answers

How universally is C99 supported?

How universally is the C99 standard supported in today's compilers? I understand that not even GCC fully supports it. Is this right? Which features of C99 are supported more than others, i.e. which can I use to be quite sure that most compilers will…
Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
43
votes
5 answers

Why class { int i; }; is not fully standard-conformant?

This is a follow-up question. In the previous question, @JohannesSchaub-litb said that the following code is not fully standard-conformant: class { int i; }; //unnamed-class definition. § 9/1 allows this! and then he added, while it is…
Nawaz
  • 353,942
  • 115
  • 666
  • 851
37
votes
6 answers

Using the correct, or preferable, not equal operator in MySQL

Which of the two (semantically equivalent) ways is preferable to test for inequality? 'foo' != 'bar' (exclamation mark and equals sign) 'foo' <> 'bar' (less than and greater than chevron symbols together) The MySQL documentation clearly indicates…
Rob Van Dam
  • 7,812
  • 3
  • 31
  • 34
34
votes
3 answers

Gnu C++ macro __cplusplus standard conform?

The Gnu C++ compiler seems to define __cplusplus to be 1 #include int main() { std::cout << __cplusplus << std::endl; } This prints 1 with gcc in standard c++ mode, as well as in C++0x mode, with gcc 4.3.4, and gcc 4.7.0. The C++11…
towi
  • 21,587
  • 28
  • 106
  • 187
34
votes
3 answers

Valid characters for URI schemes?

I was thinking about Registering an Application to a URL Protocol and I'd like to know, what characters are allowed in a scheme? Some examples: h323 (has numbers) h323:[@][:][;] z39.50r (has a . as…
32
votes
4 answers

Most efficient standard-compliant way of reinterpreting int as float

Assume I have guarantees that float is IEEE 754 binary32. Given a bit pattern that corresponds to a valid float, stored in std::uint32_t, how does one reinterpret it as a float in a most efficient standard compliant way? float…
31
votes
4 answers

Should I learn XML 1.0 or XML 1.1?

I know that a well-formed XML 1.1 is not necessarily a well-formed XML 1.0 and vice-versa. I want to learn xml formally and i was wondering whether i should learn XML 1.0 or XML 1.1? I mean would it be more effective to learn XML 1.0 or would it be…
Pacerier
  • 86,231
  • 106
  • 366
  • 634
28
votes
2 answers

__USE_FILE_OFFSET64 vs. _FILE_OFFSET_BITS=64

I am trying to maintain code that compiles on lots of different systems. I've seen a dozen different ways of asking for lseek that takes 64-bits. Some systems use lseek64, some use lseeko, some require that you define _FILE_OFFSET_BITS=64, and now I…
vy32
  • 28,461
  • 37
  • 122
  • 246
26
votes
2 answers

Do I have the guarantee that sizeof(type) == sizeof(unsigned type)?

The sizeof char, int, long double... can vary from one compiler to another. But do I have the guarantee according to the C++11 or C11 standard that the size of any signed and unsigned fundamental integral type is the same ?
Vincent
  • 57,703
  • 61
  • 205
  • 388
25
votes
1 answer

Narrowing conversion to bool in list-initialization - strange behaviour

Consider this piece of C++11 code: #include struct X { X(bool arg) { std::cout << arg << '\n'; } }; int main() { double d = 7.0; X x{d}; } There's a narrowing conversion from a double to a bool in the initialization of x.…
bogdan
  • 9,229
  • 2
  • 33
  • 48
24
votes
6 answers

How do I provide a default implementation for an Objective-C protocol?

I'd like to specify an Objective-C protocol with an optional routine. When the routine is not implemented by a class conforming to the protocol I'd like to use a default implementation in its place. Is there a place in the protocol itself where I…
23
votes
4 answers

What's the difference between "dead code" and "unreachable code"?

I thought those terms where synonymous, but a note in MISRA regarding dead code indicates this to be wrong? What's the difference? Is one a subset of the other?
Lord_Gestalter
  • 500
  • 1
  • 5
  • 14
21
votes
2 answers

What are the WONTFIX bugs on GNU/Linux and how to work around them?

Both Linux and the GNU userspace (glibc) seem to have a number of "WONTFIX" bugs, i.e. bugs which the responsible parties have declared their unwillingness to fix despite clearly violating the requirements of ISO C and/or POSIX, but I'm unaware of…
R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
21
votes
4 answers

On the std::abs function

Is the std::abs() function well defined for ALL arithmetic types in C++11 and will return |x| with no problem of approximation? A weird thing is that with g++4.7, std::abs(char), std::abs(short int), std::abs(int), std::abs(long int) and…
Vincent
  • 57,703
  • 61
  • 205
  • 388
1
2
3
26 27