-
-
Save paraboul/995466 to your computer and use it in GitHub Desktop.
C VS PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint x[3] = {0x42, 0x69, 0x13}; | |
int i = 0; | |
printf("Res : %x\n", x[i++] << 16 | x[i++] << 8 | x[i++]); | |
/* Output 0x424242 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int i = 1; | |
printf("Res : %d\n", i++ + i++); | |
Result with llvm clang and gcc : | |
para@Bohr:~/dev/libmpqsc2/$ clang x.c | |
para@Bohr:~/dev/libmpqsc2/$ ./a.out | |
Res : 3 | |
para@Bohr:~/dev/libmpqsc2/$ gcc x.c | |
para@Bohr:~/dev/libmpqsc2/$ ./a.out | |
Res : 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$x = array(0x42, 0x69, 0x13); | |
$i = 0; | |
printf("Res : %x\n", $x[$i++] << 16 | $x[$i++] << 8 | $x[$i++]); | |
/* Output 0x426913 */ | |
?> |
Different | versus << / >> operators precedence maybe ?
http://c-faq.com/expr/seqpoints.html
Since there's no good way to define it, the Standard declares that it is undefined, and that portable programs simply must not use such constructs.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Different "++" execution order