I don't think anyone who indents their code properly should care about whether the braces can be found easily in unindented code. And if the code is indented properly, in any style, each scope can...
Type: Posts; User: robatino
I don't think anyone who indents their code properly should care about whether the braces can be found easily in unindented code. And if the code is indented properly, in any style, each scope can...
Objectively, it's no less readable than K&R or Allman. In all three, to the human reader, scope is determined by a statement's horizontal offset. If the braces were invisible, the code could be...
See
http://en.wikipedia.org/wiki/Indent_style
The first code snippet is an example of K&R, the second of Allman. Allman has the advantage of treating the opening and closing braces...
The sum from n == 1 to N of 1/n is going to be something on the order of ln(N) (since the integral of 1/x is ln(x)). By drawing diagrams it's pretty easy to put both lower and upper bounds on the...
K&R2 also casts the return value of malloc() which is also generally considered a bad idea.
Casting malloc
> It should also be mentioned that in this case "new" means "1989" (if not farther back).
K&R2 uses the ANSI-style declarations, and that came out in 1988.
I'm confused about the terminology - Stroustrup in TC++PL (section 10.4.2, page 244) says "Built-in types also have default constructors (Section 6.2.8)." So, is int() (for example), which does zero...
George2's example is exactly what I have in my copy of TC++PL (9th printing, January, 1999).
Edit: 3rd edition
It's a US IBM keyboard. The "\" and "|" characters are on the same key, just under the backspace key, which is not the easiest place to reach.
Edit: It looks like this:
...
That's weird, every keyboard I've seen has "/" and "?" on the same key, including the Dell machine I'm using now, which originally had XP only installed, and came with this keyboard.
> And I really, really hate "/". It looks disgusting IMHO. So I always use "\".
Why is the DOS path character "\"?
Basically, in DOS, "/" was already being used for something else, so they...
No. In my example, since all you know is that the size is usually somewhere on the order of N (meaning it could easily be twice N, or half N, for example), then it doesn't make any sense to...
Well, suppose you have a vector v which grows to some size which you don't know exactly in advance, but you only know that the size has an theoretical upper bound of N*N, say, where N is some...
It's probably because brevity is more important in a paper book than in a source file - even Stroustrup's book leaves out std:: in its code snippets. (BTW, it's spelled "propane", without an i, and...
Yes, good point. In fact, even if it was slower in terms of CPU, the extra cache efficiency for a large array might make up for it, resulting in greater overall speed (if the bottleneck was memory...
Although if the exact size needed isn't known in advance, and one only has an upper bound which is much larger than the "average", then asking the OS to allocate that much could be counterproductive,...
I'm not a hardware person, but since the standard allows float and double to be the same size, there wouldn't be any reason to allow a smaller floating-point type if it was also slower, so I would...
If 65535 isn't big enough, the Standard guarantees that unsigned long goes up to at least 2^32 - 1 == 4294967295.
Found this by searching for "deque capacity:"
GotW #54: Using Vector and Deque
Assuming v is nonempty, of course - otherwise v[0], and hence &v[0], invokes undefined behavior (as CornedBee pointed out in a previous thread). On the other hand, v.begin() is a valid iterator...
The following is a snippet from the GCC man page (-W being the same as -Wextra):
cpjust: Yes, that works! Thanks. Sebastiani: Yes, I should have seen that, though that change by itself didn't fix it. However, also changing A* to A<T>* in the class declaration as in cpjust's...
I have a class template with an iterator as a static member. Below is a simplified version of the code. I'm having trouble with the proper syntax for the definition (line 9). Can anyone help?
...
When using vectors, reserve() can be used if you know in advance the exact maximum memory capacity needed, and the "swap trick" can be used to trim the capacity to the actual size of the vector, if...
My understanding was that in the context of C/C++, a byte by definition was whatever the size of a char is (so one can say that sizeof() returns the size in bytes, with sizeof(char) always being 1,...