Yes and control conditions are most often numeric. Look at the for() loop. |
Control condition for a for loop:
for(/*intialization*/;/*control condition */;/*iteration step/*/)
In particular,
/*control condition (boolean)*/
The control condition is a boolean.
Even if we take your example of a for loop (which is incorrect, since the initialization and the iteration step do not make up the control condition), you still have not shown why that would be more efficient than a boolean. I gave a concrete example of this:
Why should while(1){} be any more efficient thanwhile(true){}?
Yes, I know that a "bool" is an integer type internally, a byte in length. That is not what the question is asking. The question gave 4 concrete options (int, bool, bit, and long long). One of those answers is a bool. The question asks what is the "most efficient" control condition, and as it has been proven here, they are practically equivalent:
https://godbolt.org/z/muoT-_
And even if it wasn't practically equivalent, that the assembly outputs for both radically differ, this still wouldn't matter since the class doesn't teach assembly or low level constructs, so we wouldn't be expected to know that either way.
Not really, remember a bool is basically an integer that has a value of zero and not zero. |
As I stated before, this is an implementation detail. Although I am well aware of this fact, this was not covered in our class. Secondly, this statement is irrelevent. Whether a bool is implemented internally as a byte-long integer is irrelevent. To reiterate, the four choices are int, bool, long long, or bit. The question asks NOTHING about the implementation details of the four choices. This is a second-semester programming course.
My response was IGNORING all of these intricacies of implementation details, since first-year coding students aren't going to know about them considering many of them have just learned programming from this course.
What? Do you really think that C++ is only a high level language? One of the biggest features of C++ is that is can do low level work. |
Perhaps read my statement again:
Also, the course teaches nothing about low-level processor implementation, just C++
I said that the COURSE doesn't teach the implementation details of C++. This is a first-year beginner's programming course. Also, how did you come to that conclusion that I think C++ is only a high level language? I have used C++ for both high and low level projects, ranging from user software to having to write barebones inline assembly in my C++ code. I am well aware of this fact. But once again, this is irrelevent.
In a beginners programming course, they aren't going to teach you the ins and outs of the Itanium ABI or about compiler optimization techniques. Surely you know this! They will only teach you how to write software in C++, and additional details regarding compilers and assembly language are omitted for future courses. This was the case in my course.
If we ignore compiler optimization and try to put ourselves in the minds of first-year programming student's who know absolutely nothing about programming or assembly language or compilers, we could make a reasonable argument that a bool would be more efficient than an int because of the implicit conversion that has to occur (semantically). This is why I chose "B" even though a broader analysis well beyond the scope of a first year class demonstrates that it is not the case, because I tried to use what was only covered in the course syllabus even though I know more than what the course teaches.
Although, this explanation is wrong, it still makes logical sense for a first-year course that teaches nothing about what goes on under the hood. So "B" would be the most logical incorrect answer for a first-year course. The reason I selected "bool" was because I was trying to put myself in the head of the questioner in the context of a first-year course in programming. However, the questioner made the correct answer "C" which makes absolutely no sense given the constraints of a first-year course.
Now, since you and I can both see the generated assembly output for both are practically the same, we know that it isn't the case. That is the argument I wanted to give to my professor, and I just wanted to confirm this by making a thread about it here.