问题:

环境: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]的更多相关文章

  1. 解决警告“ld: warning: directory not found for option

    因为已经把文件编译到项目中,删除的话会出现找不到文件或文件夹的警告. 1选择工程, 编译的 (targets) 2选择 Build Settings 菜单 3查找 Library Search Pat ...

  2. iOS - 解决警告“ld: Warning: Directory Not Found for Option”

    有时候我们可能从项目中删除了某个目录.文件以后,编译出现警告信息: ld: warning: directory not found for option“XXXXXX” 具体类似下图: 很奇怪,为什 ...

  3. [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 ...

  4. linux0.12 解决编译问题常用命令

    解决编译问题时,经常需要修改所有的Makefile,特别定义了下面几条命令方便修改. function msed() { find -name "Makefile" -exec s ...

  5. 解决编译apache出现的问题:configure: error: APR not found . Please read the documentation - ____哊.時^随记 - 51CTO技术博客

    解决编译apache出现的问题:configure: error: APR not found . Please read the documentation - ____哊.時^随记 - 51CTO ...

  6. 16种C语言编译警告(Warning)类型的解决方法

    当编译程序发现程序中某个地方有疑问,可能有问题时就会给出一个警告信息.警告信息可能意味着程序中隐含的大错误,也可能确实没有问题.对于警告的正确处理方式应该是:尽可能地消除之.对于编译程序给出的每个警告 ...

  7. 在VS中使用Boost库出现Macro redefinition错误的解决方法(warning C4005)

    最近使用Boost库做多线程开发,可视在vs中编译工程师总是遇到Macro redefinition错误,类似下面的错误描述 1>c:\program files (x86)\microsoft ...

  8. C语言 消灭编译警告(Warning)

    如何看待编译警告 当编译程序发现程序中某个地方有疑问,可能有问题时就会给出一个警告信息.警告信息可能意味着程序中隐含的大错误,也可能确实没有问题.对于警告的正确处理方式应该是:尽可能地消除之.对于编译 ...

  9. App开发流程之使用分类(Category)和忽略编译警告(Warning)

    Category使得开发过程中,减少了继承的使用,避免子类层级的膨胀.合理使用,可以在不侵入原类代码的基础上,写出漂亮的扩展内容.我更习惯称之为"分类". Category和Ext ...

随机推荐

  1. Windows环境下搭建SVN服务器

    使用 VisualSVN Server来实现主要的 SVN功能则要比使用原始的 SVN和Apache相配合来实现源代码的 SVN管理简单的多,下面就看看详细的说明. VisualSVN Server的 ...

  2. willMoveToParentViewController和didMoveToParentViewController

    本文转载至 http://blog.csdn.net/yongyinmg/article/details/40619727 iOS 5.0 后UIViewController新增:willMoveTo ...

  3. js自动补全

    <!doctype html> <html> <style> body { margin-left: 0px; margin-top: 0px; margin-ri ...

  4. linux c编程:进程控制(三)_exec函数

    fork()函数通过系统调用创建一个与原来进程(父进程)几乎完全相同的进程(子进程是父进程的副本,它将获得父进程数据空间.堆.栈等资源的副本.注意,子进程持有的是上述存储空间的“副本”,这意味着父子进 ...

  5. Codeforces441C_Valera and Tubes(暴力)

    Valera and Tubes time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  6. [从jQuery看JavaScript]-匿名函数与闭包(Anonymous Function and Closure)

    http://blog.csdn.net/natineprince/article/details/4759533   jQuery片段: (function(){ //这里忽略jQuery所有实现 ...

  7. activiti--5 -----------------Activiti 工作流 流程各个步骤所涉及到的表

    ACT_RE_*: 'RE'表示repository. 这个前缀的表包含了流程定义和流程静态资源 (图片,规则,等等). ACT_RU_*: 'RU'表示runtime. 这些运行时的表,包含流程实例 ...

  8. 使用inotify实现linux系统下的目录变化监控

    近期,有个项目须要及时删除Nginx服务生成的缓存文件,因为不是非常了解Nginx缓存生成的策略,在网上也沒有细致找,经过大家讨论,终于希望引入liunx的inotify功能,监控某个liunx文件夹 ...

  9. spring ioc和aop理解

    1.IOC 表示控制反转. 简单点说就是原来的对象是在要使用之前通过在代码里通过new Something()的方式创建出来的: IOC则是由spring容器创建同一创建,在程序要使用到该对象的时候, ...

  10. Data Structure Array: Given an array of of size n and a number k, find all elements that appear more than n/k times

    http://www.geeksforgeeks.org/given-an-array-of-of-size-n-finds-all-the-elements-that-appear-more-tha ...