算术中使用NULL [英] NULL used in arithmetic

查看:775
本文介绍了算术中使用NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从gcc收到以下代码的警告


if(nextIs_.size()== NULL)


警告:算术中使用的NULL


我该如何解决这个问题?似乎我可以为

gcc安装一个补丁,但我没有权限这样做,我只能更改我的代码。


谢谢大家。

解决方案

asdf发布:

我收到了来自gcc的警告以下代码

if(nextIs_.size()== NULL)



NULL仅用作空指针常量。


你用它作为一个简单的整数零。


如何解决这个问题?我似乎可以为gcc安装一个补丁,但我没有这样做的权限,我只能更改我的代码。



if(!nextIs_ .size())

甚至:

if(0 == nextIs_.size())


-


Frederick Gotham


asdf写道:

我从gcc收到以下代码的警告<如果(nextIs_.size()== NULL)

警告:在算术中使用NULL

我该如何解决这个问题?似乎我可以为gcc安装一个补丁,但我没有权限这样做,我只能更改我的代码。




NULL是一个评估合法空指针常量的宏。 null

指针常量是一个值为零的整数表达式。虽然

tecnhically,你可以将它作为整数零用于其他目的,

一般意图是在测试空指针时使用NULL

和0否则。


此外,如果nextIs_是一些标准容器,size()== 0是一个潜在低效的成语。 empty()在常量时间内计算

其中size()可能需要更长时间(实际上可能需要计算

对象)。


asdf写道:

我从gcc收到以下代码的警告

if(nextIs_.size()== NULL )

警告:算术中使用NULL

如何解决这个问题?似乎我可以为gcc安装一个补丁,但我没有权限这样做,我只能更改我的代码。




Gcc使用非标准扩展,使NULL成为关键字。它的行为类似于

a适当的NULL,它只是0,但当用作

整数时会发出警告。


获取通过不滥用NULL来围绕它。你永远不应该把它写在你的地方

实际上意味着一个整数0,比如与

..size()的返回值进行比较。


用零替换NULL!


-

Phlip
http://c2.com/cgi/wiki?ZeekLand < - 不是博客!!!


I got a warning from gcc for the following code

if (nextIs_.size() == NULL)

warning: NULL used in arithmetic

how can I fix this problem? It seems that I can install a patch for
gcc, but I don''t have permission to do that, I can only change my code.

Thanks all.

解决方案

asdf posted:

I got a warning from gcc for the following code

if (nextIs_.size() == NULL)

NULL is intended to be used exclusively as a null pointer constant.

You''re using it as a simple integer zero.

how can I fix this problem? It seems that I can install a patch for
gcc, but I don''t have permission to do that, I can only change my code.


if ( !nextIs_.size() )
Or even:
if ( 0 == nextIs_.size() )

--

Frederick Gotham


asdf wrote:

I got a warning from gcc for the following code

if (nextIs_.size() == NULL)

warning: NULL used in arithmetic

how can I fix this problem? It seems that I can install a patch for
gcc, but I don''t have permission to do that, I can only change my code.



NULL is a macro evaluating to a legal null pointer constant. A null
pointer constant is an integral expression with value zero. While
tecnhically, you can use it as an integer zero for other purposes,
the general intent is to use NULL when you are testing for null pointer
and 0 otherwise.

Further, if nextIs_ is some standard container, size() == 0 is an
potentially inefficient idiom. empty() evaluates in constant time
where as size() may take longer (it may actually have to count the
objects).


asdf wrote:

I got a warning from gcc for the following code

if (nextIs_.size() == NULL)

warning: NULL used in arithmetic

how can I fix this problem? It seems that I can install a patch for
gcc, but I don''t have permission to do that, I can only change my code.



Gcc uses a non-Standard extension that makes NULL a keyword. It behaves like
a proper NULL, which is just 0, but it emits warnings when used as an
integer.

Get around it by not abusing NULL. You should never write it where you
actually mean an integer 0, such as to compare with the return value of
..size().

Replace the NULL with a zero!

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!


这篇关于算术中使用NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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