http://www.hackerschool.org/HS_Boards/zboard.php?id=QNA_programming&no=194 [º¹»ç]
ÇØÄ¿½ºÄð Ã¥À» ¸ø ºÁ¼.. Ã¥¿¡¼ ÀǵµÇÑ ¹Ù´Â ¾Ë¼ö ¾ø³×¿ä.
´Ù¸¸ ÄÚµå ÀÚü°¡ À߸øµÇ¾î ÀÖ¾î¼ Á¶±Ý ¼öÁ¤Çؼ Å×½ºÆ® ÇغýÀ´Ï´Ù
tested platform ˼
WindowsXP, VC++ °ú RH Linux, gcc ÀÔ´Ï´Ù.
¼öÁ¤µÈ ÄÚµå´Â ´ÙÀ½°ú °°½À´Ï´Ù.
#include <stdio.h>
int main(void)
{
long ip = 0x80000001;
printf("char pointer: %x %x %x\n", (char*)ip, (char*)ip+1, (char*)ip+2);
printf("int pointer: %x %x %x\n",(int*)ip, (int*)ip+1, (int*)ip+2);
printf("long int pointer: %x %x %x\n",(long int*)ip, (long int*)ip+1, (long int*)ip+2);
return 1;
}
- result on VC++:
char pointer: 80000001 80000002 80000003
int pointer: 80000001 80000005 80000009
long int pointer: 80000001 80000005 80000009
Press any key to continue
- result on gcc:
[indra@indra indra]$ ./c
char pointer: 80000001 80000002 80000003
int pointer: 80000001 80000005 80000009
long int pointer: 80000001 80000005 80000009
[indra@indra indra]$
Ã¥¿¡¼´Â °¢ type ¿¡ ÀÇÇÑ Æ÷ÀÎÅÍ ¿¬»ê °á°ú¸¦
¸»ÇÏ°í ½Í¾îÇß´ÂÁöµµ ¸ð¸¥´Ù´Â »ý°¢ÀÌ µé´õ±º¿ä.
±×·³ Áñ°øÇϼ¼¿ä..
>#include <stdio.h>
>
>int main(void)
>{
> char *cp =0x80000001;
> int *ip =0x80000001;
> long int *lp =0x80000001;
>
> printf("char pointer: %x %x %x\n",*cp, *cp+1, *cp+2);
> printf("int pointer: %x %x %x\n",ip, ip+1, ip+2);
> printf(" long int pointer: %x %x %x\n",lp, lp+1, lp+2);
> return 1;
>}
>
>
>¼Ò½º´Â ÀÌ·¸±¸¿ä..
>
>ÄÄÆÄÀÏ ¿¡·¯ ¸Þ½ÃÁö´Â ´ÙÀ½°ú °°½À´Ï´Ù.
>
>
>D:\Program Files\Microsoft Visual Studio\source\Cpp1.cpp(5) : error C2440: 'initializing' : cannot convert from 'const unsigned int' to 'char *'
> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
>
>
>D:\Program Files\Microsoft Visual Studio\source\Cpp1.cpp(6) : error C2440: 'initializing' : cannot convert from 'const unsigned int' to 'int *'
> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
>
>
>D:\Program Files\Microsoft Visual Studio\source\Cpp1.cpp(7) : error C2440: 'initializing' : cannot convert from 'const unsigned int' to 'long *'
> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
>
>Error executing cl.exe.
>
>Cpp1.exe - 3 error(s), 0 warning(s)
>
>C¿¡ ´ëÇÑ Áö½ÄÀÌ ¸¹ÀÌ ºÎÁ·ÇÏ¿©
>
>¿©·¯ºÐµé²² µµ¿òÀ» ûÇÕ´Ï´Ù.
>
>ÄÄÆÄÀÏÀº VC++ ¿¡¼ Çß½À´Ï´Ù.
>
>°Ë»öÇØ º¸´Ï ºñ½ÁÇÑ °Ô½Ã¹°Àº Àִµ¥ Àú ¿¡·¯¸Þ½ÃÁö´Â ¾Æ´Ñµí Çϱº¿ä..
>
|
Hit : 4810 Date : 2003/11/11 03:59
|