Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

BlueCobold

Community-Fossil

Beiträge: 10 738

Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer

  • Private Nachricht senden

21

10.04.2013, 12:41

Links und rechts spielt (in diesem Fall) keine Rolle. Es kommt nur auf die Typen an.

Und da hat Konvertierung von bool in int den Vorzug über eine Konvertierung von int nach bool? Mensch, sprich doch einfach, ich muss Dir ja alles aus der Nase ziehen.
Teamleiter von Rickety Racquet (ehemals das "Foren-Projekt") und von Marble Theory

Willkommen auf SPPRO, auch dir wird man zu Unity oder zur Unreal-Engine raten, ganz bestimmt.[/Sarkasmus]

22

10.04.2013, 13:09

§5.10 (Equality operators) Abs. 1
The == (equal to) and the != (not equal to) operators have the same semantic restrictions, conversions, and
result type as the relational operators except for their lower precedence and truth-value result.

§5.9 (Relational operators) Abs. 2
The usual arithmetic conversions are performed on operands of arithmetic or enumeration type.

§5 (Expressions) Abs. 10
Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield
result types in a similar way. The purpose is to yield a common type, which is also the type of the result.
This pattern is called the usual arithmetic conversions, which are defined as follows:
[...]
Otherwise, the integral promotions (4.5) shall be performed on both operands. Then the following rules shall be applied to the promoted operands:
- If both operands have the same type, no further conversion is needed.
[...]

§3.9.1 (Fundamental types) Abs. 6
Values of type bool are either true or false. [ Note: There are no signed, unsigned, short, or long
bool types or values. — end note ] Values of type bool participate in integral promotions.

§4.5 (Integral promotions) Abs. 6
A prvalue of type bool can be converted to a prvalue of type int, with false becoming zero and true
becoming one.
"Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: Nothing works and they don’t know why." - Anon

BlueCobold

Community-Fossil

Beiträge: 10 738

Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer

  • Private Nachricht senden

23

10.04.2013, 13:15

Aha. Schon spannend, ich kann mich in all den Jahren Programmierung nicht erinnern jemals einen bool mit einem Integral verglichen zu haben. Falls ich's also jemals machen sollte, weiß ich jetzt wenigstens, was C++ daraus macht ;)
Teamleiter von Rickety Racquet (ehemals das "Foren-Projekt") und von Marble Theory

Willkommen auf SPPRO, auch dir wird man zu Unity oder zur Unreal-Engine raten, ganz bestimmt.[/Sarkasmus]

Schrompf

Alter Hase

Beiträge: 1 470

Wohnort: Dresden

Beruf: Softwareentwickler

  • Private Nachricht senden

24

10.04.2013, 14:47

Verstehe ich das richtig?

Quellcode

1
2
3
4
5
6
bool ja = 1; // wird zu true
if( ja == 1 )
  DasStimmt();
bool jawoll = 2; // wird auch zu true
if( jawoll == 2 )
  NöDasStimmtNicht();

Funky! Man lernt doch immer was dazu.
Häuptling von Dreamworlds. Baut aktuell an nichts konkretem, weil das Vollzeitangestelltenverhältnis ihn fest im Griff hat. Baut daneben nur noch sehr selten an der Open Asset Import Library mit.

25

10.04.2013, 14:53

Wenn du meinst, dass die zweite Funktion nicht ausgeführt wird, dann ja.
"Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: Nothing works and they don’t know why." - Anon

Werbeanzeige