Slight Typos? Graphic Language and Other Curiosities
-
Slight Typos? Graphic Language and Other Curiosities
Difficulty: 8 / 10
Sometimes even small and hard-to-see typos can accidentally have a significant effect on code. To illustrate how hard typos can be to see, and how easy phantom typos are to see accidentally even when they're not there, consider these examples.Problem
Guru Questions
Answer the following questions without using a compiler.1. What is the output of the following program on a standards-conforming C++ compiler?
#include <iostream>
int main()
{
int x = 1;
for( int i = 0; i < 100; ++i );
// What will the next line do? Increment???????????/
++x;
std::cout << x;
}2. How many distinct errors should be reported when compiling the following code on a conforming C++ compiler?
struct X {
static bool f( int* p )
{
return p && 0[p] and not p[1:>>p[2];
};
};Solution
Coming soon...
-
http://www.gotw.ca/gotw/086.htm
warum postest du das hier?
Achja: die Lösung (sofern ich mich nicht vertan habe) ist:
- 1
- 0
warum das so ist, verrate ich aber nicht (schliesslich will ich niemanden den spass wegnehmen)
-
antwort auf frage 2 ist falsch, shade
das kann garnicht gehn
-
außerdem gibts "and" und "not" garnicht
-
wieso bei 1) nicht 2? zuerst ist x==1, dann wird ++x gemacht.
Bei 2) ist doch bei "p[1:>>p[2];" der : nicht erlaubt und es fehlt eine schließende ]
-
doch, das sind Trigraphen
-
not #define not ! [keyword in C++] The macro yields the operator !. and #define and && [keyword in C++] The macro yields the operator &&.
-
und wo sind die definiert???
-
das sind Schlüsselwörter
-
Original erstellt von <gerd>:
antwort auf frage 2 ist falsch, shade
das kann garnicht gehnhabs mir nochmal angesehen und meine Antwort stimmt
jage es doch durch den gcc - wirst schon sehendas stichwort trigraph ist ja schon gefallen - also schaut euch mal an welche es da gibt (in C muss man die ios646.h (oder so ähnlich) einbinden, in C++ sind die trigraphen bestandteil der sprache)
was machen die trigraphen
??/
:>>
and
noteinige wurden ja schon genannt
-
Davon ist nur einer ein Trigraph. Merke: Ein alternatives Zeichen ist kein Trigraph.
-
Meine ich auch. Ein Trigraph wird immer eingeleitet durch ?? und wird eingesetzt wenn man Programme im ISO Zeichensatz schreiben will.