日期:2014-05-16  浏览次数:20597 次

一段可以在linux下编译并且运行正确的程序,在windows下编译也通不过.为什么?
代码如下:

#include   <stdio.h>

typedef   unsigned   char BYTE;

BYTE*   GetCurDate()
{
BYTE   *TempDate;
*(TempDate)   =   0x31;
*(TempDate+1)   =   0x32;
*(TempDate+2)   =   0x33;
return   TempDate;  
}

main()
{
printf( "windows   32bit   platform   point   test   function!\n ");
BYTE   bCurStore=0;
BYTE   *Date   =   &bCurStore;
BYTE   *bCurDate;
bCurDate   =   GetCurDate();
*(bCurDate+3)=0x0;
printf( "bCurDate   =   %s\n ",bCurDate);
}


linux环境:fc4   gcc   4.0
windows环境:windows   xp   ,vc   6.0


------解决方案--------------------
#include <stdio.h>

typedef unsigned char BYTE;

BYTE* GetCurDate(BYTE* Temp)
{
BYTE *TempDate=Temp;
*(TempDate) = 0x31;
*(TempDate+1) = 0x32;
*(TempDate+2) = 0x33;
return TempDate;
}

int main()
{
printf( "windows 32bit platform point test function!\n ");
BYTE bCurStore=0;
BYTE *Date = &bCurStore;
BYTE *bCurDate;
bCurDate = GetCurDate(Date);
*(bCurDate+3)=0x0;
printf( "bCurDate = %s\n ",bCurDate);

return 0;
}

除了这里有个错误(笔误?)typedef unsigned charBYTE;
编译可以通过
xp2+vc6.0