错误:从'void *'转换为'int'在makefile中丢失精度[-fpermissive] [英] error: cast from ‘void*’ to ‘int’ loses precision [-fpermissive] in makefile

查看:4021
本文介绍了错误:从'void *'转换为'int'在makefile中丢失精度[-fpermissive]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ubuntu 12.04 LTS(64位)上编译以下makefile时遇到此错误:

while compiling following makefile on ubuntu 12.04 LTS (64-bit) encountered with this error:

Ana.cxx:21:46: error: cast from ‘void*’ to ‘int’ loses precision [-fpermissive]

在这行:

21 : TThread::Printf("Start of Ana %x \n" ,(int)ptr);

这里是makefile:

here is the makefile:

ObjSuf        = o
SrcSuf        = cxx
DllSuf        = so
ExeSuf        =
OutPutOpt     = -o 
CXXFLAGS      = -g -Wall -fPIC -DOSF1 
CXX           = g++
CCFLAGS       = -g -Wall -DOSF1 
CC            = gcc
LD            = g++
LDFLAGS       = -g
SOFLAGS       = -shared
ROOTCFLAGS   := $(shell root-config --cflags) -DFILL_ON_FLY 
ROOTLIBS     := $(shell root-config --libs) -lNew -lThread -lMinuit -lPhysics
ROOTGLIBS    := $(shell root-config --glibs)  -lNew -lThread
EVENTO        = BINAEvent.$(ObjSuf) Ana.$(ObjSuf) BINAEventDict.$(ObjSuf)     mwpc_software.o tcpip.o Genbood.o  
EVENTS        = BINAEvent.$(SrcSuf) Ana.$(SrcSuf) BINAEventDict.$(SrcSuf) mwpc_software.c tcpip.c Genbood.c 
EVENTLIB      = $(ROOTGLIBS)
EVENTEXE      = ana
OBJS          = $(EVENTO)
    .SUFFIXES: .$(SrcSuf) .$(ObjSuf) .$(DllSuf)
    .PHONY:    Aclock Hello Tetris
     $(EVENTEXE):     $(OBJS)
         $(LD) $^ $(ROOTLIBS) $(OutPutOpt) $@
         @echo "$@ done"
     clean:
         @rm -f $(OBJS) core *~ *Dic* ana *.o
     .SUFFIXES: .$(SrcSuf)
     BINAEvent.$(ObjSuf): BINAEvent.h
       BINAEventDict.$(SrcSuf): BINAEvent.h BINAEventLinkDef.h
       @echo "Generating dictionary $@..."
       @rootcint -f $@ -c $^
      .$(SrcSuf).$(ObjSuf):
       $(CXX) $(CXXFLAGS) $(ROOTCFLAGS) -c $<
    .c.$(ObjSuf):
     $(CXX) $(CXXFLAGS) $(ROOTCFLAGS) -c $<

投入此方法的正确方法是什么?

What is the proper way to cast this?

提前感谢。

推荐答案

错误与makefile无关。

The error has nothing to do with the makefile. The bug is in the source, on the line shown by the error.

在您的平台上,指针不适合 int

On your platform, a pointer does not fit in an int. If you cast a pointer to an integer, you should probably use intptr_t or uintptr_t from stdint.h which are guaranteed to be big enough.

我不知道 TThread :: Printf

I don't know what TThread::Printf is, it's not standard. But the usual way to print a pointer address with printf is to pass the pointer as void* and use the %p format specifier. This is likely to be the case with TThread::Printf as well.

这篇关于错误:从'void *'转换为'int'在makefile中丢失精度[-fpermissive]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆