免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1674 | 回复: 4
打印 上一主题 下一主题

[C++] 请教在g++下面,这份简单的代码编译不过,有解决办法吗? [复制链接]

论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:52:30
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-05-16 13:13 |只看该作者 |倒序浏览
  1. #include "stdio.h"
  2. #include <time.h>
  3. #include <sys/time.h>
  4. #include <math.h>
  5. #include <string.h>
  6. #include <sys/ioctl.h>
  7. #include <unistd.h>
  8. #include <fcntl.h>
  9. #include "errno.h"
  10. #include <pthread.h>
  11. #include <stdint.h>
  12. #include <signal.h>
  13. #include<sys/time.h>
  14. #include <sys/types.h>
  15. #include <sys/stat.h>
  16. #include <dirent.h>
  17. #include <sys/types.h>
  18. #include <sys/socket.h>
  19. #include <sys/syscall.h>
  20. #include <sys/select.h>
  21. #include <ctype.h>
  22. #include <limits.h>


  23. typedef enum {
  24.   QMI_RESULT_TYPE_MIN_ENUM_VAL_V01 = -2147483647, /**< To force a 32 bit signed enum.  Do not change or use*/
  25.   QMI_RESULT_SUCCESS_V01 = 0,
  26.   QMI_RESULT_FAILURE_V01 = 1,
  27.   QMI_RESULT_TYPE_MAX_ENUM_VAL_V01 = 2147483647 /**< To force a 32 bit signed enum.  Do not change or use*/
  28. }qmi_result_type_v01;


  29. typedef struct {

  30.   qmi_result_type_v01 result;
  31.   /**<   Result code
  32.                             - QMI_RESULT_SUCCESS
  33.                             - QMI_RESULT_FAILURE
  34.                           */

  35. }qmi_response_type_v01;  /* Type */


  36. typedef struct {

  37.   /* Mandatory */
  38.   /*  Result Code */
  39.   /**<   Standard response type. */

  40.   /* int ab; */ //但如果我加上这个int ab后,再用g++ test.c,是可以编译过的。
  41.   qmi_response_type_v01 resp;

  42.   /**<   \n
  43.        (Extended sizes to accommodate LTE.)
  44.   */
  45. }nas_get_rf_band_info_resp_msg_v01;  /* Message */



  46. int main(int argc, char **argv)
  47. {
  48.     int s;
  49.     int ret;

  50.     nas_get_rf_band_info_resp_msg_v01 getBandResp = {0};
  51.         while (1);
  52.    
  53.     return 0;
  54. }
复制代码
上面是我提取出来的代码。鉴于项目的原因,我们不能修改makefile,也最好不要先分配getBandResp后再用memset,请问大侠有什么解决办法呢?
谢谢!

如果用gcc编译,是可以的,但g++编译就出错:
test111.c: In function 鈥榠nt main(int, char**)鈥

                                                  test111.c:333:55: error: invalid conversion from 鈥榠nt鈥to 鈥榪mi_result_type_v01鈥[-fpermissive]
     nas_get_rf_band_info_resp_msg_v01 getBandResp = {0};

论坛徽章:
36
子鼠
日期:2013-08-28 22:23:29黄金圣斗士
日期:2015-12-01 11:37:51程序设计版块每日发帖之星
日期:2015-12-14 06:20:00CU十四周年纪念徽章
日期:2015-12-22 16:50:40IT运维版块每日发帖之星
日期:2016-01-25 06:20:0015-16赛季CBA联赛之深圳
日期:2016-01-27 10:31:172016猴年福章徽章
日期:2016-02-18 15:30:3415-16赛季CBA联赛之福建
日期:2016-04-07 11:25:2215-16赛季CBA联赛之青岛
日期:2016-04-29 18:02:5915-16赛季CBA联赛之北控
日期:2016-06-20 17:38:50技术图书徽章
日期:2016-07-19 13:54:03程序设计版块每日发帖之星
日期:2016-08-21 06:20:00
2 [报告]
发表于 2015-05-16 14:36 |只看该作者
如果用gcc编译,是可以的,但g++编译就出错:
test111.c: In function 鈥榠nt main(int, char**)鈥

                                                  test111.c:333:55: error: invalid conversion from 鈥榠nt鈥to 鈥榪mi_result_type_v01鈥[-fpermissive]
     nas_get_rf_band_info_resp_msg_v01 getBandResp = {0};


楼主贴的报错也是醉了。。

论坛徽章:
36
子鼠
日期:2013-08-28 22:23:29黄金圣斗士
日期:2015-12-01 11:37:51程序设计版块每日发帖之星
日期:2015-12-14 06:20:00CU十四周年纪念徽章
日期:2015-12-22 16:50:40IT运维版块每日发帖之星
日期:2016-01-25 06:20:0015-16赛季CBA联赛之深圳
日期:2016-01-27 10:31:172016猴年福章徽章
日期:2016-02-18 15:30:3415-16赛季CBA联赛之福建
日期:2016-04-07 11:25:2215-16赛季CBA联赛之青岛
日期:2016-04-29 18:02:5915-16赛季CBA联赛之北控
日期:2016-06-20 17:38:50技术图书徽章
日期:2016-07-19 13:54:03程序设计版块每日发帖之星
日期:2016-08-21 06:20:00
3 [报告]
发表于 2015-05-16 14:37 |只看该作者
改成
  1. nas_get_rf_band_info_resp_msg_v01 getBandResp = {qmi_result_type_v01(0)};
复制代码
或者
  1. nas_get_rf_band_info_resp_msg_v01 getBandResp = {QMI_RESULT_SUCCESS_V01};
复制代码

论坛徽章:
36
子鼠
日期:2013-08-28 22:23:29黄金圣斗士
日期:2015-12-01 11:37:51程序设计版块每日发帖之星
日期:2015-12-14 06:20:00CU十四周年纪念徽章
日期:2015-12-22 16:50:40IT运维版块每日发帖之星
日期:2016-01-25 06:20:0015-16赛季CBA联赛之深圳
日期:2016-01-27 10:31:172016猴年福章徽章
日期:2016-02-18 15:30:3415-16赛季CBA联赛之福建
日期:2016-04-07 11:25:2215-16赛季CBA联赛之青岛
日期:2016-04-29 18:02:5915-16赛季CBA联赛之北控
日期:2016-06-20 17:38:50技术图书徽章
日期:2016-07-19 13:54:03程序设计版块每日发帖之星
日期:2016-08-21 06:20:00
4 [报告]
发表于 2015-05-16 14:38 |只看该作者
不过尽量不要用implicity为好

论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:52:30
5 [报告]
发表于 2015-05-16 18:28 |只看该作者
cool!
Thanks!
回复 3# cokeboL


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP