解决编译warning:warning: ‘MeteringUnit::voltage_gain_’ will be initialized after [-Wreorder]
问题:
环境:ubuntu 12.04,g++版本4.6.3,编译目标文件时出现warnings:
u1204@u1204-zhw:~/hwsvn/2sw/4prj_mips/UCP_rt5350/src/trunk$ make clean;make
rm -f *.o local_ctrl
g++ -g3 -Wall -o0 -c msgrcv_cmd.cpp -o msgrcv_cmd.o
In file included from msgrcv_cmd.h:24:0,
from msgrcv_cmd.cpp:30:
controller.h: In constructor ‘MeteringUnit::MeteringUnit(size_t, double, double, double)’:
controller.h:92:12: warning: ‘MeteringUnit::voltage_gain_’ will be initialized after [-Wreorder]
controller.h:91:12: warning: ‘double MeteringUnit::current_gain_’ [-Wreorder]
controller.h:77:5: warning: when initialized here [-Wreorder]
g++ -g3 -Wall -o0 -c controller.cpp -o controller.o
In file included from controller.cpp:21:0:
controller.h: In constructor ‘MeteringUnit::MeteringUnit(size_t, double, double, double)’:
controller.h:92:12: warning: ‘MeteringUnit::voltage_gain_’ will be initialized after [-Wreorder]
controller.h:91:12: warning: ‘double MeteringUnit::current_gain_’ [-Wreorder]
controller.h:77:5: warning: when initialized here [-Wreorder]
g++ -g3 -Wall -o0 -c thread.cpp -o thread.o
g++ -g3 -Wall -o0 -c ini_file.cpp -o ini_file.o
g++ -g3 -Wall -o0 -c main_ctrl.cpp -o main_ctrl.o
In file included from main_ctrl.cpp:25:0:
controller.h: In constructor ‘MeteringUnit::MeteringUnit(size_t, double, double, double)’:
controller.h:92:12: warning: ‘MeteringUnit::voltage_gain_’ will be initialized after [-Wreorder]
controller.h:91:12: warning: ‘double MeteringUnit::current_gain_’ [-Wreorder]
controller.h:77:5: warning: when initialized here [-Wreorder]
解决办法:
1. 出问题的地方在头文件controller.h中,
class MeteringUnit {
public:
MeteringUnit(size_t port_num = 1, double pgain = 1.0, double cgain = 1.0, double vgain = 1.0)
: port_(port_num), power_gain_(pgain), voltage_gain_(vgain), current_gain_(cgain) { }
~MeteringUnit();
void Refresh();
double Power() const;
double Current() const;
double Voltage() const;
private:
size_t port_;
operation* mu_op_;
static const SensorType sensor_typ_ = EMETER;
private:
static const int emeter_pulse_const_ = 3200;
double power_gain_;
double current_gain_;
double voltage_gain_;
double power_;
double current_;
double voltage_;
int gpqs1_; // GP1/GQ1/GS1(0x50/0x51/0x52)
int gphs1_; // Gphs1(0x6d)
int p1offset_; // P1offset(0x65)
};
从编译后的提示,已经可以很明白地看出错在什么地方了,
MeteringUnit::voltage_gain_应该在double MeteringUnit::current_gain_之后初始化。
也就是说,构造函数中变量初始化的顺序与该成员变量在类MeteringUnit中定义的顺序不一致。
将其中的两行
MeteringUnit(size_t port_num = 1, double pgain = 1.0, double cgain = 1.0, double vgain = 1.0)
: port_(port_num), power_gain_(pgain), voltage_gain_(vgain), current_gain_(cgain) { }
改为
MeteringUnit(size_t port_num = 1, double pgain = 1.0, double cgain = 1.0, double vgain = 1.0)
: port_(port_num), power_gain_(pgain), current_gain_(cgain), voltage_gain_(vgain) { }
重新编译,问题解决。
u1204@u1204-zhw:~/hwsvn/2sw/4prj_mips/UCP_rt5350/src/trunk$ make clean;make
rm -f *.o local_ctrl
g++ -g3 -Wall -o0 -c msgrcv_cmd.cpp -o msgrcv_cmd.o
g++ -g3 -Wall -o0 -c controller.cpp -o controller.o
g++ -g3 -Wall -o0 -c thread.cpp -o thread.o
g++ -g3 -Wall -o0 -c ini_file.cpp -o ini_file.o
g++ -g3 -Wall -o0 -c main_ctrl.cpp -o main_ctrl.o
g++ -o local_ctrl msgrcv_cmd.o controller.o thread.o ini_file.o main_ctrl.o -L../../drivers -lphysicalop -lpthread
解决编译warning:warning: ‘MeteringUnit::voltage_gain_’ will be initialized after [-Wreorder]的更多相关文章
- 解决警告“ld: warning: directory not found for option
因为已经把文件编译到项目中,删除的话会出现找不到文件或文件夹的警告. 1选择工程, 编译的 (targets) 2选择 Build Settings 菜单 3查找 Library Search Pat ...
- iOS - 解决警告“ld: Warning: Directory Not Found for Option”
有时候我们可能从项目中删除了某个目录.文件以后,编译出现警告信息: ld: warning: directory not found for option“XXXXXX” 具体类似下图: 很奇怪,为什 ...
- [WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored (webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true')
WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored (webxml attribu ...
- linux0.12 解决编译问题常用命令
解决编译问题时,经常需要修改所有的Makefile,特别定义了下面几条命令方便修改. function msed() { find -name "Makefile" -exec s ...
- 解决编译apache出现的问题:configure: error: APR not found . Please read the documentation - ____哊.時^随记 - 51CTO技术博客
解决编译apache出现的问题:configure: error: APR not found . Please read the documentation - ____哊.時^随记 - 51CTO ...
- 16种C语言编译警告(Warning)类型的解决方法
当编译程序发现程序中某个地方有疑问,可能有问题时就会给出一个警告信息.警告信息可能意味着程序中隐含的大错误,也可能确实没有问题.对于警告的正确处理方式应该是:尽可能地消除之.对于编译程序给出的每个警告 ...
- 在VS中使用Boost库出现Macro redefinition错误的解决方法(warning C4005)
最近使用Boost库做多线程开发,可视在vs中编译工程师总是遇到Macro redefinition错误,类似下面的错误描述 1>c:\program files (x86)\microsoft ...
- C语言 消灭编译警告(Warning)
如何看待编译警告 当编译程序发现程序中某个地方有疑问,可能有问题时就会给出一个警告信息.警告信息可能意味着程序中隐含的大错误,也可能确实没有问题.对于警告的正确处理方式应该是:尽可能地消除之.对于编译 ...
- App开发流程之使用分类(Category)和忽略编译警告(Warning)
Category使得开发过程中,减少了继承的使用,避免子类层级的膨胀.合理使用,可以在不侵入原类代码的基础上,写出漂亮的扩展内容.我更习惯称之为"分类". Category和Ext ...
随机推荐
- 如何使CSS--better(系列一)
我们想一下以下问题: 1.什么样子的css代码才是高效的? 2.什么样子的css代码才是便于维护的? 3.什么样子的css才是可扩展的? 带着以下问题咱们简单的说一下css的“性能”问题 虽然我技术不 ...
- Linux进程间通信(一) - 管道
管道(pipe) 普通的Linux shell都允许重定向,而重定向使用的就是管道. 例如:ps | grep vsftpd .管道是单向的.先进先出的.无结构的.固定大小的字节流,它把一个进程的标准 ...
- [T-SQL] 获取拼音
)) ) as begin ) ) declare @i int declare @words_len int declare @unicode int set @words = ltrim(rtri ...
- 【BZOJ4010】[HNOI2015]菜肴制作 拓扑排序
[BZOJ4010][HNOI2015]菜肴制作 Description 知名美食家小 A被邀请至ATM 大酒店,为其品评菜肴. ATM 酒店为小 A 准备了 N 道菜肴,酒店按照为菜肴预估的质量从高 ...
- 记录-移动端网页触摸内容滑动js插件
需求: 在webapp中需要左右滑动手机,移动主页的轮播图.也可用在引导页(欢迎页)的大图左右滑动 可用: 百度:swiper插件 在项目中导入插件,这里只有部分代码,具体百度swiper <l ...
- IIS架构介绍
IIS7及以上版本提供的请求-处理架构包括以下内容: Windows Process Activation Service(WAS)可以让站点支持更多协议,不仅仅是HTTP和HTTPS 可以通过增加或 ...
- 九度OJ 1344:可乐瓶展览 (DP)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:430 解决:76 题目描述: 众所周知JOBDU旗下的JOBCOLA公司是文明全球的著名可乐制造商,与其它可乐公司不同的是,JOBCOLA可 ...
- Webpack探索【1】--- 基础知识
本文主要说明Webpack的一些基础内容.
- Android笔记之OnLongClickListener
OnLongClickListener中的回调函数boolean onLongClick(View v),其返回值的官方释义如下 如果这个回调消耗了长点击,则返回true,否则返回false. 即使翻 ...
- 页游手游服务器(一)c实现拓展lua网络
把工作几年服务器相关的部分内容,通过服务器解决方案,做一次总结.整个实现的主体是lua脚本,lua实现主要缺少的两大块:1网络部分2数据库部分这两部分必须通过c/c++做扩展先来做net,主要是服务器 ...