Takatalab
¥á¥ó¥Ð¡¼/y-takata/misc/n=n++;
¤ò¥Æ¥ó¥×¥ì¡¼¥È¤Ë¤·¤ÆºîÀ®
³«»Ï¹Ô:
*n = n++; [#dfc58ac0]
** ¤Þ¤¨¤ª¤ [#w51c240c]
__'n = n++;'__ ¤È¤¤¤¦ÂåÆþʸ¤ÎÏäòMÀèÀ¸¤«¤éʹ¤¤¤Æ¡¢µ¤¤Ë¤Ê...
¼Â¤ÏMÀèÀ¸¤¬¸À¤Ã¤Æ¤ª¤é¤ì¤¿¤Î¤Ï°Ê²¼¤Î¤è¤¦¤Ê¥³¡¼¥É¤Î¤³¤È¤Ç¡¢...
class Some {
int n;
void foo(int n) {
this.n = n++;
}
}
** ËÜÂê [#h7334e70]
ʸ»úÄ̤ê __'n = n++;'__ ¤È¤¤¤¦ÂåÆþʸ¤À¤È¤É¤¦¤Ê¤ë¤Î? ¤È¤¤...
int n = 0;
n = n++;
¤È¤¤¤¦¥³¡¼¥É¤ò¹Í¤¨¤ë¤È¡¢
+ ¼° __'n++'__ ¤ÎÃÍ¤Ï 0 ¤Ê¤Î¤Ç¡¢ÂåÆþ±é»»¤Ë¤è¤Ã¤Æ n ¤Ë 0 ...
+ ++±é»»»Ò¤Ë¤è¤ê¡¢n ¤¬¥¤¥ó¥¯¥ê¥á¥ó¥È¤µ¤ì¤ë¡£
¤È¤¤¤¦2¤Ä¤Î½èÍý¤¬¹Ô¤ï¤ì¤ë¤Ï¤º¤À¤±¤ì¤É¤â¡¢½ç½ø¼¡Âè¤Ç·ë²Ì¤Ï...
__'n = n + 1;'__ ¤È¤¤¤¦½ñ¤Êý¤È __'n++;'__ ¤È¤¤¤¦½ñ¤Êý¤ò...
*** K&R [#i5685b96]
K&R((¥«¡¼¥Ë¥Ï¥ó, ¥ê¥Ã¥Á¡¼: ¥×¥í¥°¥é¥ß¥ó¥°¸À¸ìC, Âè2ÈÇ, ÀÐ...
*** GCC [#m221ee18]
GCC¤À¤È¤É¤¦¤«? ¤È¤¤¤¦¤È¡¢·ë²Ì n ¤¬¥¤¥ó¥¯¥ê¥á¥ó¥È¤µ¤ì¤ë¤Î...
¤Ç¡¢__'-Wsequence-point'__¥ª¥×¥·¥ç¥ó¤òÉÕ¤±¤ë¤È¡¢
warning: operation on 'n' may be undefined
¤È¤¤¤¦·Ù¹ð¤¬½Ð¤ë¤è¤¦¤Ë¤Ê¤ë¡Ê¥«¥·¥³¥¤¡Ë¡£
man¥Ú¡¼¥¸¤Î __'-Wsequence-point'__ ¤Î¹à¤ò¸«¤ë¤È¡¢
>(ά)
>Examples of code with undefined behavior are "a = a++;",...
>(ά)
¤È¤¤¤¦¤³¤È¤Ç¡¢__'n = n++;'__ ¤Ï undefined behavior ¤Ê¥³¡¼...
** Java [#zf3cfd23]
¤¸¤ã¤¢ Java ¤Ï? ¤È¤¤¤¦¤È¡¢¤³¤ì¤¬¥¨¥é¡¼¤¸¤ã¤Ê¤¤¤Î¤À¤Ê¡£¡Ê...
int n = 0;
n = n++;
System.out.println("n = " + n);
¤È¤¤¤¦¥³¡¼¥É¤Ï¤Á¤ã¤ó¤È¥³¥ó¥Ñ¥¤¥ë¤Ç¤¤ë¡£¤Ç¡¢·ë²Ì¤Ï __'n =...
*** ¸À¸ì»ÅÍÍ [#z7f8d4ae]
[[Java¸À¸ì»ÅÍÍ>http://java.sun.com/docs/books/jls/third_e...
__'n = n++;'__ ¤Î²ò¼á¤Ï¡ÖEvaluate Operands before Operati...
¡Ö__'n = a++;'__ ¤Ï¤è¤¯¤Æ __'n = n++;'__ ¤Ï¤À¤á¡×¤È¤«¸À¤¤...
*** ¤È¸À¤¦¤³¤È¤Ï [#c4d58fec]
¤¸¤ã¤¢ __' a[i] = i++;'__ ¤ä __'a[i++] = i;'__ ¤âok¤Ê¤ï...
int[] a = new int[] { 0, 0, 0, 0, 0 };
int i = 1;
a[i] = i++; // (*1)
a[i++] = i; // (*2)
for (int j = 0; j < a.length; j++) {
System.out.print(a[j] + " ");
}
System.out.println();
ÌäÂê¤Ê¤¯¥³¥ó¥Ñ¥¤¥ë¤Ç¤¤ë¡£·ë²Ì¤Ï __'0 1 3 0 0'__¡£
__'='__ ¤Ë¤Ä¤¤¤Æ¤â¡ÖEvaluate Left-Hand Operand First¡×([[...
*** ¤ª¤Þ¤±¤Î¼Â¸³ [#zc960952]
¤³¤Î¸À¸ì»ÅÍͽñ¤È¤«¡ÈThe Java Programming Language((K.Arnol...
²¼µ¤ÏThe Java Programming Language¤Î¡ø9.2.1¤ÎÎã¡£
int i = 16;
System.out.println(++i + " " + i++ + " " + i);
¡Ä¤Ï¤¤¤Ï¤¤¡¢JavaŪ¤Ë¤Ïok¤Ê¤ó¤Ç¤·¤ç? ¤è¤¯¤ï¤«¤ê¥Þ¥·¥¿¡£__'(...
¤Á¤Ê¤ß¤Ë __'17 17 18'__ ¤Èɽ¼¨¤µ¤ì¤ë¤Î¤¬Àµ²ò¡£
¤â¤Á¤í¤ó C ¤Ç¤Ï½èÍý·Ï°Í¸¤Î¤Ï¤º¡Ä¡¢¤È¤¤¤¦¤³¤È¤Ç»î¤·¤Æ¤ß¤ë...
int i = 16;
printf("%d %d %d\n", ++i, i++, i);
K&R¤Ë¤â»÷¤¿Î㤬¡Ö°¤¤Îã¡×¤È¤·¤Æµó¤¬¤Ã¤Æ¤¤¤ë¡Ê°ú¿ô¤Îɾ²Á½ç...
| powerpc-apple-darwin8-gcc-4.0.1 | __'18 17 18'__ |
| i386-redhat-linux-gcc-4.1.2 | __'18 16 18'__ |
2ÈÖÌܤÀ¤±¾®¤µ¤¤Ãͤˤʤë¤Î¤¬¤Á¤ç¤Ã¤È°Õ³°¡£
º£ÅÙ¤Ï __'sprintf'__ ¤È __'strcat'__ ¤òÁȤ߹ç¤ï¤»¤Æʸ»úÎó...
#include <stdio.h>
#include <string.h>
char *tostr(int i) {
static char buf[3][256];
static int bufc = 0;
sprintf(buf[bufc], "%d ", i);
return buf[bufc++];
}
int main() {
int n = 16;
printf("%s\n", strcat(strcat(tostr(++n), tostr(n++))...
return 0;
}
·ë²Ì¤Ï°Ê²¼¤ÎÄ̤ꡣpowerpc¤Ïº¸°ú¿ôÍ¥Àè¡¢i386¤Ï±¦°ú¿ôÍ¥Àè¡¢...
| powerpc-apple-darwin8-gcc-4.0.1 | __'17 17 18'__ |
| i386-redhat-linux-gcc-4.1.2 | __'18 16 16'__ |
** ·ëÏÀ [#x6dddc3d]
__'n = n++;'__ ¤È¤¤¤¦Ê¸¤Ï¡¢
- Java¤Ç¤ÏÀµ¤·¤¤Ê¸¡Ê¤Ç¤â n ¤ÎÃͤÏÊѲ½¤·¤Ê¤¤¤Î¤Ç̵°ÕÌ£¡Ë
- C¤Ç¤Ï¿¶¤ëÉñ¤¤¤Ï½èÍý·Ï°Í¸¡Ê¤Ç¤â¥¤¥ó¥¯¥ê¥á¥ó¥È¤µ¤ì¤ë¾ì¹ç...
- GCC 4 ¤Ç __'-Wall'__ ¤ò¤Ä¤±¤ì¤Ð·Ù¹ð¤¬É½¼¨¤µ¤ì¤ë
½ªÎ»¹Ô:
*n = n++; [#dfc58ac0]
** ¤Þ¤¨¤ª¤ [#w51c240c]
__'n = n++;'__ ¤È¤¤¤¦ÂåÆþʸ¤ÎÏäòMÀèÀ¸¤«¤éʹ¤¤¤Æ¡¢µ¤¤Ë¤Ê...
¼Â¤ÏMÀèÀ¸¤¬¸À¤Ã¤Æ¤ª¤é¤ì¤¿¤Î¤Ï°Ê²¼¤Î¤è¤¦¤Ê¥³¡¼¥É¤Î¤³¤È¤Ç¡¢...
class Some {
int n;
void foo(int n) {
this.n = n++;
}
}
** ËÜÂê [#h7334e70]
ʸ»úÄ̤ê __'n = n++;'__ ¤È¤¤¤¦ÂåÆþʸ¤À¤È¤É¤¦¤Ê¤ë¤Î? ¤È¤¤...
int n = 0;
n = n++;
¤È¤¤¤¦¥³¡¼¥É¤ò¹Í¤¨¤ë¤È¡¢
+ ¼° __'n++'__ ¤ÎÃÍ¤Ï 0 ¤Ê¤Î¤Ç¡¢ÂåÆþ±é»»¤Ë¤è¤Ã¤Æ n ¤Ë 0 ...
+ ++±é»»»Ò¤Ë¤è¤ê¡¢n ¤¬¥¤¥ó¥¯¥ê¥á¥ó¥È¤µ¤ì¤ë¡£
¤È¤¤¤¦2¤Ä¤Î½èÍý¤¬¹Ô¤ï¤ì¤ë¤Ï¤º¤À¤±¤ì¤É¤â¡¢½ç½ø¼¡Âè¤Ç·ë²Ì¤Ï...
__'n = n + 1;'__ ¤È¤¤¤¦½ñ¤Êý¤È __'n++;'__ ¤È¤¤¤¦½ñ¤Êý¤ò...
*** K&R [#i5685b96]
K&R((¥«¡¼¥Ë¥Ï¥ó, ¥ê¥Ã¥Á¡¼: ¥×¥í¥°¥é¥ß¥ó¥°¸À¸ìC, Âè2ÈÇ, ÀÐ...
*** GCC [#m221ee18]
GCC¤À¤È¤É¤¦¤«? ¤È¤¤¤¦¤È¡¢·ë²Ì n ¤¬¥¤¥ó¥¯¥ê¥á¥ó¥È¤µ¤ì¤ë¤Î...
¤Ç¡¢__'-Wsequence-point'__¥ª¥×¥·¥ç¥ó¤òÉÕ¤±¤ë¤È¡¢
warning: operation on 'n' may be undefined
¤È¤¤¤¦·Ù¹ð¤¬½Ð¤ë¤è¤¦¤Ë¤Ê¤ë¡Ê¥«¥·¥³¥¤¡Ë¡£
man¥Ú¡¼¥¸¤Î __'-Wsequence-point'__ ¤Î¹à¤ò¸«¤ë¤È¡¢
>(ά)
>Examples of code with undefined behavior are "a = a++;",...
>(ά)
¤È¤¤¤¦¤³¤È¤Ç¡¢__'n = n++;'__ ¤Ï undefined behavior ¤Ê¥³¡¼...
** Java [#zf3cfd23]
¤¸¤ã¤¢ Java ¤Ï? ¤È¤¤¤¦¤È¡¢¤³¤ì¤¬¥¨¥é¡¼¤¸¤ã¤Ê¤¤¤Î¤À¤Ê¡£¡Ê...
int n = 0;
n = n++;
System.out.println("n = " + n);
¤È¤¤¤¦¥³¡¼¥É¤Ï¤Á¤ã¤ó¤È¥³¥ó¥Ñ¥¤¥ë¤Ç¤¤ë¡£¤Ç¡¢·ë²Ì¤Ï __'n =...
*** ¸À¸ì»ÅÍÍ [#z7f8d4ae]
[[Java¸À¸ì»ÅÍÍ>http://java.sun.com/docs/books/jls/third_e...
__'n = n++;'__ ¤Î²ò¼á¤Ï¡ÖEvaluate Operands before Operati...
¡Ö__'n = a++;'__ ¤Ï¤è¤¯¤Æ __'n = n++;'__ ¤Ï¤À¤á¡×¤È¤«¸À¤¤...
*** ¤È¸À¤¦¤³¤È¤Ï [#c4d58fec]
¤¸¤ã¤¢ __' a[i] = i++;'__ ¤ä __'a[i++] = i;'__ ¤âok¤Ê¤ï...
int[] a = new int[] { 0, 0, 0, 0, 0 };
int i = 1;
a[i] = i++; // (*1)
a[i++] = i; // (*2)
for (int j = 0; j < a.length; j++) {
System.out.print(a[j] + " ");
}
System.out.println();
ÌäÂê¤Ê¤¯¥³¥ó¥Ñ¥¤¥ë¤Ç¤¤ë¡£·ë²Ì¤Ï __'0 1 3 0 0'__¡£
__'='__ ¤Ë¤Ä¤¤¤Æ¤â¡ÖEvaluate Left-Hand Operand First¡×([[...
*** ¤ª¤Þ¤±¤Î¼Â¸³ [#zc960952]
¤³¤Î¸À¸ì»ÅÍͽñ¤È¤«¡ÈThe Java Programming Language((K.Arnol...
²¼µ¤ÏThe Java Programming Language¤Î¡ø9.2.1¤ÎÎã¡£
int i = 16;
System.out.println(++i + " " + i++ + " " + i);
¡Ä¤Ï¤¤¤Ï¤¤¡¢JavaŪ¤Ë¤Ïok¤Ê¤ó¤Ç¤·¤ç? ¤è¤¯¤ï¤«¤ê¥Þ¥·¥¿¡£__'(...
¤Á¤Ê¤ß¤Ë __'17 17 18'__ ¤Èɽ¼¨¤µ¤ì¤ë¤Î¤¬Àµ²ò¡£
¤â¤Á¤í¤ó C ¤Ç¤Ï½èÍý·Ï°Í¸¤Î¤Ï¤º¡Ä¡¢¤È¤¤¤¦¤³¤È¤Ç»î¤·¤Æ¤ß¤ë...
int i = 16;
printf("%d %d %d\n", ++i, i++, i);
K&R¤Ë¤â»÷¤¿Î㤬¡Ö°¤¤Îã¡×¤È¤·¤Æµó¤¬¤Ã¤Æ¤¤¤ë¡Ê°ú¿ô¤Îɾ²Á½ç...
| powerpc-apple-darwin8-gcc-4.0.1 | __'18 17 18'__ |
| i386-redhat-linux-gcc-4.1.2 | __'18 16 18'__ |
2ÈÖÌܤÀ¤±¾®¤µ¤¤Ãͤˤʤë¤Î¤¬¤Á¤ç¤Ã¤È°Õ³°¡£
º£ÅÙ¤Ï __'sprintf'__ ¤È __'strcat'__ ¤òÁȤ߹ç¤ï¤»¤Æʸ»úÎó...
#include <stdio.h>
#include <string.h>
char *tostr(int i) {
static char buf[3][256];
static int bufc = 0;
sprintf(buf[bufc], "%d ", i);
return buf[bufc++];
}
int main() {
int n = 16;
printf("%s\n", strcat(strcat(tostr(++n), tostr(n++))...
return 0;
}
·ë²Ì¤Ï°Ê²¼¤ÎÄ̤ꡣpowerpc¤Ïº¸°ú¿ôÍ¥Àè¡¢i386¤Ï±¦°ú¿ôÍ¥Àè¡¢...
| powerpc-apple-darwin8-gcc-4.0.1 | __'17 17 18'__ |
| i386-redhat-linux-gcc-4.1.2 | __'18 16 16'__ |
** ·ëÏÀ [#x6dddc3d]
__'n = n++;'__ ¤È¤¤¤¦Ê¸¤Ï¡¢
- Java¤Ç¤ÏÀµ¤·¤¤Ê¸¡Ê¤Ç¤â n ¤ÎÃͤÏÊѲ½¤·¤Ê¤¤¤Î¤Ç̵°ÕÌ£¡Ë
- C¤Ç¤Ï¿¶¤ëÉñ¤¤¤Ï½èÍý·Ï°Í¸¡Ê¤Ç¤â¥¤¥ó¥¯¥ê¥á¥ó¥È¤µ¤ì¤ë¾ì¹ç...
- GCC 4 ¤Ç __'-Wall'__ ¤ò¤Ä¤±¤ì¤Ð·Ù¹ð¤¬É½¼¨¤µ¤ì¤ë
¥Ú¡¼¥¸Ì¾: