常见的编程错误

编程不经历错误或警告,怎能见彩虹,没有人能随随便便成为高手。身为程序员的我们,如果哪一天没有了错误或警告的提示,一定会有一种不祥的预感,对吧,都懂的抓狂。编程N年来,碰到过的问题多得自己都记不清了,你也一样,如果可以选择,我愿时光倒流,真希望都能记下来,现在就可以写本《错误集》了,偷笑。下面是我心情好时,有想法时,随手记下的几个错误或警告,遗憾的是,这些年,就记下那么几个而已,见笑了,希望能给像我一样在路上的人有些帮助或提示。

1.提领指向不完全类型的指针

struct hostent

{

       char    *h_name;              

       char    **h_aliases;

       int     h_addrtype;

       int     h_length;

       char    **h_addr_list;

       #defineh_addr h_addr_list[0]

};

没有包含头文件,哈哈

    比如这个结构,尽管在头文件中已经包含或定义,但对这个结构体的成员(hptr->h_name)变量进行访问时,编译无法通过,显示编译器错误提示为“提领指向不完全类型的指针”。

对于结构体来说虽然所有的变量默认都是公有的,但是,如果想访问里面的成员变量,必须有包含对其结构的定义,否则出现如上的错误,c编译器将无法识别结构里面的变量,一般想操作结构体里的成员变量,都是通过调用结构体中定义的函数接口,来取得结构体中的值,如果想直接访问,在头文件或源文件中加入结构体的定义就行了

2.警告:赋值 makes pointer from integer without a cast

同样因为没包含头文件。


3.previous implicitdeclaration of 'Base64_Code' was here

    Base64_Code函数未定义,如果要使用 Base64_Code函数,则要先定义。


4.警告:use of cast expressions aslvalues is deprecated

(short)buf[2] =atoi(&data[4]);不赞成把强制类型转换的结果作为左值


5.warning: initializationdiscards qualifiers from pointer target type

initialization取消了指针目标类型的限定。


6.glibc detected *** free():invalid next size (normal)

    是内存泄露的问题。

    (1)一般是free了没有分配的内存

    (2)还有就是分配了内存忘记释放也有可能会出现这样的问题。

    (3)最后查出来是数组循环的时候越界了 , 写到了其他的内存里面, 然后一free那个区域就出现了这样的问题。

    是有allocate引起的,一个debug的方法是把你怀疑的矩阵(比如释放了就会报内存错误)定义成静态的,这样如果出现越界,会报段错误。依次检查是否你的数组真的越界了。

7. undefined referenceto `__gxx_personality_v0'

    gcc main.c animal.o后,出现这个错误(c与c++混合编程中),解决:gcc main.c animal.o -lstdc++   错误原因:是因为你用gcc编译.cpp文件.按系统默认.cpp文件是c++的文件格式


8.rmmod:gpio_i2c_LVP1008.ko: Resource temporarily unavailable

    [root: 1st]#lsmod //查看一下当前加载的模块

    driver 1256 0- Live 0xbf00c000

    device 1560 0- Live 0xbf006000

    bus 1336 2driver,device, Live 0xbf000000 //模块的引用计数,bus模块被device和driver引用

    [root: 1st]# rmmodbus //如果你要卸载bus模块,它会提示出错,要先卸载driver和device

    rmmod: remove'bus': Resource temporarily unavailable

    [root: 1st]#rmmod driver

    usb driverbye!

    [root: 1st]#rmmod device //卸载device时,内核自动调用device结构体中指定的release函数

    <kernel>release

    usb device bye!

    [root: 1st]#lsmod //bus的引用计数为0,可以卸载bus了

    bus 1336 0 -Live 0xbf012000

    [root: 1st]#rmmod bus

    usb bus bye!

9. error: expectedidentifier before numeric constant错误。

     原因:定义的enum结构体与其它处的宏定义有冲突。

10.warning: missing bracesaround initializer

    原因:结构体初始化失败。

11.too many agrument

    一种原因:参数多于10个。

12. /usr/bin/ld: cannot find-lxxx

    原因:找不到对应库文件。其中,-lxxx表示链接库文件 libxxx.so。

    一般出现这种错误有以下几种原因:

        1.系统缺乏对应的库文件;

        2.版本不对应;

        3.库文件的链接错误;

        4.库文件路径设置问题。

     对应第一第二种情况,可以通过下载安装lib来解决,ubuntu大多数可以直接通过apt-get来安装:

       apt-get install libxxx-dev

      一般遇到这种问题笔者第一时间也是会去检查系统是否已安装该lib或者是否已选择正确版本(只是习惯问题),如果还是不能解决问题,那么,引起错误的原因不是链接错误就是库文件路径问题了。

        通过find或者locate指令定位到链接文件,查看链接文件是否正确的指向了我们希望的lib,如果不是,用ln -sf */libxxx.so.x */libxxx.so 指令修改它。

        如果是库文件路径引发的问题,可以到/etc/ld.so.conf.d目录下,修改其中任意一份conf文件,(可以自建conf,以方便识别)将lib所在目录写进去,然后在终端输入ldconfig 更新缓存。

13.在控制台提示:Semop lock failureIdentifier removed

   Semop unlock failure Identifier removed

  解决办法:运行应用程序,比如:client-qws& 去掉-qws 因为只有Server 才需要 -qws&。&为后台运行的标识。

14.Segmentation fault

    数组越界或访问空、野指针或未被初始化的指针都会出现这个问题。

15.安装VMware: The MSI'C:\Users\dell\AppData\Local\Temp\vmware_1344246656\vmwarevmcisockets64.msi'failed

    清空注册表中vmware信息(或者下载一个VM卸载工具):

       1、开始->运行,输入:regedit;

       2、在注册表中,找到:HKEY_LOCAL_MACHINE\SOFTWARE\VMware并删除。

VMware Workstation unrecoverable error:(vmx)错误

解决:删除或修改虚拟机目录下拓展名为.vmss(33.3M)文件,再次启动即可。 一般为centos5.6-d4cf3290.vmss文件。

16.arm板运行时出现Can't retrieve login name 

    原因:RTP的JRTPLIB库中的RTPSession中的Create->InternalCreate->CreateCNAME中,有对用户名进行一定操作,其中的getlogin_r(),getlogin()和getenv()操作都会因为用户名为空,而返回错误 ERR_RTP_SESSION_CANTGETLOGINNAME。
解决的方式有3种:1)export   LOGNAME=root  2)大部分开发板还是需要用户名登陆的,即在文件系统完全启动后再运行,也能解决。 3)因为板子上的文件系统有时不需要用户名就可以直接登录,而在我们可以通过修改JRTPLIB库的CreateCNAME源代码来为系统默认设置一个用户名。在RTPSession.cpp的第1400行。

17. warning: control reaches end of non-void function
    解决:函数结尾无return返回值导致的,在函数最后加一句return 0。
18.could not read symbols: 文件格式错误
19.insmod: can't insert 'xxx.ko': unknown symbol in module, or unknown parameter
    解决办法:通过信息中的绿色背景信息,可以找到解决办法:在内核模块源码文件中添加MODULE_LICENSE("GPL");
20.MMB LEAK(pid=2876): 0xC68B9000, 32768 bytes, '' mmz_userdev_release: mmb<0xC68B9000> mapped to userspace 0x40f50000 will be force unmaped!
    解决:客服端跟服务器端进行socket通信时,服务器异常断开,而客户端并不知道服务器已经断开,继续向服务器发送数据,从而引发了SIGPIPE信号,内核响应这个信号,强行终止了程序;
    #include <signal.h>    signal(SIGPIPE, SIG_IGN);
    还有一种可能就是代码中循环判断嵌套层次达到四次,被GCC编译器优化后运行时会出现这种错误。只要降低循环判断嵌套层次即可。
21.mount: 192.168.1.211:/work/nfs failed, reason given by server: Permission denied
1)修改 /etc/exports
/work/nfs   192.168.1*(rw,insecure,sync)   //网段不对
2)然后重启服务
service nfs restart
22. 开发板能ping通路由器,但ping不通外网
   vi /etc/resolv.conf
    nameservice 192.168.2.1
    因为1,2网段不断切换,但域名服务器未改变。

 

    我想,错误不在于多寡以及自己笔记记下了多少,而是在于能养成一种良好的习惯,编程以逻辑为重,比如最为简单的if(0 == i),错误的锁定及调试手段#define _DEBUG(msg...)    printf("[ %s,%s, %d ] ",__FILE__, __FUNCTION__, __LINE__);  printf(msg);printf("\r\n")等等等等…………

    注:本文经过整理,转载自http://blog.csdn.net/sbvfhp/article/details/9239531

转载于:https://www.cnblogs.com/elisha-blogs/p/3989840.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
vmware 11 最新的unlock2.0 Mac OS X Unlocker for VMware V2.0 ================================= 1. Introduction --------------- Unlocker 2 is designed for Workstation 11, Player 7 and Fusion 7. If you are using an earlier product please continue using Unlocker 1 Version 2 has been tested against: * Workstation 11 on Windows and Linux * Player 7 on Windows and Linux * Fusion 7 on Mavericks and Yosemite * (Currently is does not work on ESXi 6.0) The patch code carries out the following modifications dependent on the product being patched: * Fix vmware-vmx and derivatives to allow Mac OS X to boot * Fix vmwarebase .dll or .so to allow Apple to be selected during VM creation * A copy of the latest VMware Tools for OS X is included Note that not all products recognise the darwin.iso via install tools menu item. You will have to manually mount the darwin.iso for example on Workstation and Player. The vmwarebase code does not need to be patched on OS X so you will see a message on those systems telling you that it will not be patched. In all cases make sure VMware is not running, and any background guests have been shutdown. The code is now Python as it makes the Unlocker easier to run and maintain on ESXi. There are some challenges to write the code as ESXi has a subset of Python 2.7 which constrains some modules that can be used. 2. Prerequisites ---------------- The code requires Python 2.7 to work. Most Linux distros and OS X ship with a compatible Python interpreter and should work without requiring any additional software. Windows will need a version of Python installed and the code has been tested against: CPython - https://www.python.org/downloads/ ActiveState Python - http://www.activestate.com/activepython/downloads IronPython - https://ironpython.codeplex.com/releases/view/169382 The python.exe file must be on the executable PATH. If it is not on PATH please edit win-install.cmd to point to the installation path. 3. Limitations -------------- The Unlocker currently does not work on ESXi 6. The Unlocker does not remove the check for server versions for OS X Leopard and Snow Leopard (10.5 and 10.6). +-----------------------------------------------------------------------------+ | IMPORTANT: | | ========== | | | | If you create a new VM using version 11 hardware VMware will stop and | | create a core dump.There are two options to work around this issue: | | | | 1. Change the VM to be HW 10 - this does not affect performance. | | 2. Edit the VMX file and add: | | smc.version = 0 | | | +-----------------------------------------------------------------------------+ Work continues to find solutions to the limitations. 4. Windows ---------- On Windows you will need to either run cmd.exe as Administrator or using Explorer right click on the command file and select "Run as administrator". win-install.cmd - patches VMware win-uninstall.cmd - restores VMware 5. Linux --------- On Linux you will need to be either root or use sudo to run the scripts. You may need to ensure the Linux scripts have execute permissions by running chmod +x against the 2 files. lnx-install.sh - patches VMware lnx-uninstall.sh - restores VMware 6. Mac OS X ----------- On Mac OS X you will need to be either root or use sudo to run the scripts. This is really only needed if you want to use client versions of Mac OS X. You may need to ensure the OS X scripts have execute permissions by running chmod +x against the 2 files. osx-install.sh - patches VMware osx-uninstall.sh - restores VMware Thanks to Zenith432 for originally building the C++ unlocker and Mac Son of Knife for all the testing and support. History ------- 12/12/14 1.0.0 - First release (c) 2011-2014 Dave Parsons
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值