现在的位置: 首页 > 综合 > 正文

c与c++程序的不同对调试的影响

2013年10月07日 ⁄ 综合 ⁄ 共 732字 ⁄ 字号 评论关闭

1.c函数中变量的定义必须在函数前面全部定义完成,而c++则可在函数中间用到变量的时候再定义;

////////C函数

char hostname[128];  
 char *temp_info;
 struct hostent *pHostent;
 struct sockaddr_in sa; 

 gethostname(hostname, sizeof(hostname));
 pHostent = gethostbyname(hostname);  
 memcpy(&sa.sin_addr.s_addr,pHostent->h_addr_list[0],pHostent->h_length); 
 temp_info=inet_ntoa(sa.sin_addr);
 strcpy(info->local_PIPA,temp_info); 

//////////C++函数

 char hostname[128];  
 char *temp_info;

 gethostname(hostname, sizeof(hostname));
 struct hostent *pHostent = gethostbyname(hostname);  

 struct sockaddr_in sa; 
 memcpy(&sa.sin_addr.s_addr,pHostent->h_addr_list[0],pHostent->h_length); 
 temp_info=inet_ntoa(sa.sin_addr);
 strcpy(info->local_PIPA,temp_info);  

2.关于结构的定义

c定义为:struct hostent *pHostent;
c++定义为:hostent *pHostent;

抱歉!评论已关闭.