English 中文(简体)
ASSERT是否多余?
原标题:Is ASSERT redundant?
ASSERT(pointer);
pointer->x;

在这项法典中,ASSERT似乎是多余的。 如果点员为NUL,点工和点工;x将失败。 我的论点是否正确?

最佳回答

声明的重要(如果不是主要)目的是文件,即应在《守则》的某一时刻持有的持股人。 <代码>assert 如果瓦伦特人破碎只是ake,尽管这是非常有用的,但也可能破坏该方案。 我这样说,在一个典型的方案中,90%的断言是,显然可以失败,永远不会失败。 换言之,<代码>assert在很大程度上是一种正式评论语言。 正式化的含义是,这些“意见”是用相同的语言书写的,法典的其余部分(C/C++)是用普通英语书写的。

在你的法典样本中,有人告诉你,这里的点人不应被否定。 因此,情况就是如此。 从这个意义上讲,<代码>assert并非多余。

就执行流量而言,<代码>>>srt总是多余的,这就是为什么通常不将主张编入法典的发布版本。 没有什么东西可以阻止你坚持释放守则中的说法,但通常通过引入一种特殊的“释放主张”。 无论如何,使该守则的主要功能取决于一项主张采取的行动,这不是一项良好的方案拟订做法。 就《守则》的主要功能而言,提名应当是多余的。

问题回答

是的,但pointer->x (I presume)将以无节制的方式失败,而assert<>>>>srt/code>将失败,并准确告诉你什么地方。

从某种意义上讲,<代码>assert当然是多余的always

不是多余的。 这种说法不会在任何坏事发生之前停止执行。 另一方面,如果你不提及一个无效的点,你可能会造成真正的腐败,或者至少是不受控制的ault,而不是控制堕胎。

<代码>ASSERT不是C标准的一部分,因此,任何事情都不可能。

 #define ASSERT(x) do { 
     x = malloc ( sizeof *x ); 
     memset ( x, 0, sizeof *x );
     } while ( 0 )

<代码>assert>是一个不同的事项。

有些人有“ASSERT宏观法,称为变板,有些人有其他 de或伐木,使用加工前者的强化特征。

你们真的必须说,宏观对任何人来说是怎样的,知道这是否重要。

On some cases assert can be used for debugging http://simonwillison.net/2008/May/22/debugging/

<>ASSERT也可用于检查可能不会造成坠毁的无效或不合逻辑的条件。 这里举了一个可恶的例子:

void cpu_hog(int duration)
{
    int start_time = (int) time(NULL);
    int end_time   = start_time + duration;

    ASSERT(end_time > start_time);  /* If this fails, "int" is too small. */

    while ((int) time(NULL) < end_time)
        ;
}

缩略语:<代码>ASSERT的多数支持者建议,在你撰写该守则时,你只使用该代码验证其假设(例如,点名不是NCL,或者不能出现条件)。 它一般认为“bad <>>>><>>> >关于使用的意思是,把与用户有关的错误或预期会出现的例外情形(例如,整个磁盘)困惑不解,因为(1)ASSERT只适用于装饰,(2)即使你提倡生产精减代码,它也会坠毁,而不是处理可耻的条件。

无国界记者协会不会失败。 此时此刻,我们就不再夸张。 这将不影响释放建筑。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签