int x[10];
for(inti = 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.
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.
@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:
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.
@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?
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:
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?
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.
> 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)
@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?
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.).