All Questions

405
votes
8answers
35990 views

Undefined, unspecified and implementation-defined behavior

What is the difference between undefined, unspecified, and implementation-defined behavior in C and C++?
29
votes
5answers
5167 views

How to implement memmove in standard C without an intermediate copy?

From the man page on my system: void *memmove(void *dst, const void *src, size_t len); DESCRIPTION The memmove() function copies len bytes from string src to string dst. ...
53
votes
3answers
1352 views

In C99, is f()+g() undefined or merely unspecified?

I used to think that in C99, even if the side-effects of functions f and g interfered, and although the expression f() + g() does not contain a sequence point, f and g would contain some, so the behav...
88
votes
2answers
5642 views

Does this code from "The C++ Programming Language" 4th edition section 36.3.6 have well-defined behavior?

In Bjarne Stroustrup's The C++ Programming Language 4th edition section 36.3.6 STL-like Operations the following code is used as an example of chaining: void f2() { std::string s = "but I have he...
10
votes
2answers
1569 views

Unspecified, undefined and implementation defined behavior WIKI for C

Although there is plentiful of links about this subject on SO, I think that there is something missing: a clear explanation in plain language of what are the differences between unspecified behavior (...
13
votes
3answers
2094 views

Is it unspecified behavior to compare pointers to different arrays for equality?

The equality operators have the semantic restrictions of relational operators on pointers: The == (equal to) and the != (not equal to) operators have the same semantic restrictions, conversions, a...
15
votes
5answers
2933 views

Why does a main function without a return statement return value 12?

I have written a program that prints a table. I have not included the return syntax in the main function, but still whenever I type echo $? it displays 12. My source code : #include <stdio.h> ...
4
votes
2answers
238 views

Is indexing a new map element and having something that reads it assigned to it undefined behaviour, or just unspecified?

After answering this question, there was a long discussion over whether the code in question was undefined behaviour or not. Here's the code: std::map<string, size_t> word_count; word_count["a"...
14
votes
2answers
423 views

Is there a sequence point between a function call returning an object and a method call on that object?

If I write f(x)->g(args, ...) can I rely on a sequence point after f(x) before the evaluation of args, ...? I can see arguments both ways: §1.9.17 "When calling a function (whether or not the f...
44
votes
3answers
2039 views

Move semantics and function order evaluation

Suppose I have the following: #include <memory> struct A { int x; }; class B { B(int x, std::unique_ptr<A> a); }; class C : public B { C(std::unique_ptr<A> a) : B(a->x, std...

Previous Next