More FAQ updates

Pages: 1234
off-by-one errors:
1
2
3
4
int x[10];
for(int i = 1; i < 10; ++i);
for(int i = 0; i < 11; ++i);
for(int i = 0; i <= 10; ++i);


Also similar, but more often encountered issues with descending index.

Edit: Reading set amount of variables without checking for input validity, leading to many prompts to enter value without actually stopping to take one if error is made during input.
Last edited on
Could you put something in there about use the prefix increment instead of postfix because it always annoys me how so many people use the pointless and more inefficient (I know not by much, but it has no advantage and is done many times) postfix increment.
Also, on a side note, maybe the fact that range based uses colon not semi colon, which can trip people up.
Last edited on
@MiiNiPaa
That's the kind of thing I had in mind, I guess. The Tutorial seems to have a pretty good overview of the for loop...

Reading a list of items is definitely going to be a FAQ, probably under I/O section, but I am considering a link to it from somewhere in beginners...

@shadowmouse
Alas, I think pre-vs-post increment isn't a battle to pick in the FAQ. For intrinsic types the choice is irrelevant. IIRC, some compilers can change a simple myclass++ into a ++myclass, though I don't know if this is really a safe optimization. (I would have to learn more about compiler behavior before answering that question.)

As for the range-based for loop, I've been spoiled by Tcl's foreach and I wish that it were possible to easily traipse across multiple ranges simultaneously:

for (auto x : xs; auto y : ys)

or select multiple elements:

for (auto x, y : xs)

(Instead you have to zip them:

for (auto xy_tuple : zipiter( xs, ys )) )
> http://www.cplusplus.com/faq/beginners/undefined/
The links to Marshall Cline’s C++ FAQ-Lite contain just a forwar to isocpp, it may be better to simply use the isocpp link.
https://isocpp.org/wiki/faq/misc-technical-issues#double-mod-betw-seq-pt
https://isocpp.org/wiki/faq/misc-technical-issues#sequence-points


About the integer division, I'm also unfamiliar with the symbol and have issues reading it.
- 2 divided by 1 is 0 and the remainder is 2 (wrong)
- 2 divides 1 with a 0 result and a 2 remainder (wrong)
- 2 divided by 1 is have 0 remainder and the result is 2 (correct, but not what you were trying to show)
Haven't you ever done long or short division? That symbol, otherwise known as the bus shelter, means that the number on the left goes into the digit on the right, the number above it times and the entire division produces a remainder of what is on the top right after the R: It seemed fairly clear to me to show that 2 goes into 1 0 times and produces a remainder of 2, which is how short (or long I think) division would deal with the problem if you refuse to go into decimal places.
Haven't you ever done long or short division?
Almost everyone from Europe will not understand this notation: https://en.wikipedia.org/wiki/Long_division#Notation_in_non-English-speaking_countries
Oh, cool. I'd never realised there was more than one way to set out long or short division.
@ne555
Yes, the super faq is a new thing. I have many, many links to update to it.

@long division
Alas, I did not realize that the notation was so different for this -- the US notation is fairly ubiquitous on the net and in math books/sites.

How should I rephrase it so that all can understand? Multiple examples? As a process? Just as "1 <solidus> 2 = 0 remainder 2"?
I may be missing something, but from the main page, I can't seem to find a way to get to the FAQ page. There's the "C++ language FAQ" under Info, but how does one get to cplusplus.com/faq?

Also the precedence FAQ link is bad:
http://www.cplusplus.com/faq/beginners/precedence/
I can't seem to find a way to get to the FAQ page
I believe it is because faq is still unfinished.

Also the precedence FAQ link is bad
And several dovens of other links. Those are unfinished sections.
New FAQ: using namespace std;
http://www.cplusplus.com/faq/beginners/using-namespace-std/

Whew. That one's a potential hot-button topic. How'd I do?
Well, it is fine, all sources which are commonly linked are here (isocpp link and SO answer)
However it looks more about ADL than namepaces. Maybe visually separate it in two parts, each with own further reading section (namespaces would get SO and "Why I hate namespace" links) and add short summary of potential problems with using directive, referring to links for further explanation?


About using namespace std;. I have run into exact name clashing problem mentioned on isocpp faq code while explaining scope, visibility and name shadowing:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <algorithm>
using namespace std;
void func1();
void func2();
int count;

int main()
{
    int i;
    for (i=0; i<10; i++) {
        count = i * 2;
        func1();
    }
}
void func1()
{
    func2();
    cout << "count: " << count;
    cout << '\n';
}
void func2()
{
    int count;
    for(count=0; count<3; count++) std::cout<< '.';
}
@Duoas

025 - - how do I write an OS


My current operating system source code is in 32bit protected mode and I have some basic console manipulation functions.

Screen shot here: http://postimg.org/image/5cey6acyj/

I can explain how and why hardware works to a certain extent and take the reader through simple yet valuable functions when working at the hardware level.

I could throw in those tools I made in C++ to show how programming can be useful?

However after the boot sector and bootstrap it's in C not C++. I'd wonder if this is an issue?

EDIT: Some source from MiOS - stdio16.asm: http://pastebin.com/7pzhNf7Q

Still needs some work, thinking of making an extended version for the bootstrap as I couldn't make anything too bloated for the bootsector, that FAT12 code really eats into the space.

I had a method I used on linux before I used FAT12 where I just loaded the image with raw code, storing different machine code at different sector offsets on the disk. Everything is easy in real mode, I'm finding protected mode to be a cruel mistress.
Last edited on
> It seemed fairly clear to me to show that 2 goes into 1 0 times and produces a remainder of 2
>> Just as "1 <solidus> 2 = 0 remainder 2"
You did the division incorrectly. 1 divided by 2 is 0 and has a remainder of 1
Text works for me.


About using namespace, you say
> (You do not have the right to manipulate the user’s namespace.)
perhaps a little clarification that including a header is equivalent to copy-paste its content, so the sources now have the using.
(that there is no "file scope" as it may in another language)
Heh, LOL... yeah... I, uh, can do math...

fixed. http://www.cplusplus.com/faq/beginners/integer-division/

@megatron 0
All that is worth some articles. The FAQ is basically going to say that writing an OS is hard, and to point people to some useful resources to get started, like osdev.org.

@MiiNiPaa
I'll try to reformat to make it a little more organized. Some of these FAQs, I admit, I haven't much interest in writing... The "using namespace" one is among them. (So if someone wants to volunteer a better text...)

Something as involved as the code you posted (while simple, it demonstrates more than three related issues) might do better as an Article?

[edit]
@ne555
You're right about the cut-n-paste nature of include files -- that should be in the FAQ. I'll see if I can update the following two to say that:
http://www.cplusplus.com/faq/compiling/files/#headers
http://www.cplusplus.com/faq/beginners/multiple-sources/ #header
Does that sound right?

[edit 2]
There will be more about this in the compiling section.
Last edited on
Alright, here's the FAQ on naming things.
http://www.cplusplus.com/faq/beginners/variable-names/

I'm not sure I'm entirely pleased with it, but unless there's something you can point out that's wrong I'm done with it.
That looks really good and probably quite useful for people who aren't particularly used to programming. (Many people while in my class who were learning kept naming things variable1 and variable2). A couple of things I'd suggest specific little things for is don't do variable1 and variable2 and maybe standard names that make things easier to read (i for index, j for next nested index, T for first template type e.t.c.).
Alright. It still has to be packed into a pretty table, but before I do that, are there any additions or modifications to the "names to use" you can think of?
http://www.cplusplus.com/faq/beginners/variable-names/#common
A couple-ish more common names for scratch variables that I have bumped into from time to time?

lhs and rhs

1
2
inline bool operator==(const Examples& lhs, const Example& rhs) {
    // etc 


and that

1
2
3
4
5
6
class Examples {
public:
    Example();
    Examples(const Example& that);
    Examples& operator=(const Example& that);
    // etc 


Andy
Last edited on
Oh yeah! I knew I'd miss some good ones. (Keep them coming and I'll put them in!)

Also, I updated the command-line arguments FAQ.
http://www.cplusplus.com/faq/beginners/command-line-arguments/
Pages: 1234